Bug 244070 - [dstore] DStoreHostShell#exit() does not terminate child processes
Summary: [dstore] DStoreHostShell#exit() does not terminate child processes
Status: RESOLVED FIXED
Alias: None
Product: Target Management
Classification: Tools
Component: RSE (show other bugs)
Version: 3.0   Edit
Hardware: All All
: P4 major (vote)
Target Milestone: 3.1 M5   Edit
Assignee: David McKnight CLA
QA Contact: Martin Oberhuber CLA
URL:
Whiteboard:
Keywords: helpwanted
Depends on: 161774 244130 244132
Blocks: 250319 263669
  Show dependency tree
 
Reported: 2008-08-13 15:59 EDT by Chris Recoskie CLA
Modified: 2009-02-08 18:39 EST (History)
2 users (show)

See Also:


Attachments
patch to issue cancel command on DStoreHostShell.exist() (1.62 KB, patch)
2009-02-03 14:28 EST, David McKnight CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Recoskie CLA 2008-08-13 15:59:41 EDT
java.lang.Process.destroy() is meant to forcibly terminate a process.  HostShellProcessAdapter.destroy() does not forcibly terminate the process however.  Instead, it calls IHostShell.exit(), which sends the text "exit" to the shell to cause it to, well, exit.  The upshot of this is that it actually waits for any running processes to finish before the exit command is sent (or more correctly, the shell doesn't get the exit command until its foreground process finishes).

This makes HostShellProcessAdapter.destroy() pretty useless.  We are using this currently to manage remote processes in PTP, but this means we cannot kill them, so we cannot do things like cancel a remote build that is in progress.

If there is a better way to manage remote processes that avoids this issue we would be open to switching to it.
Comment 1 Martin Oberhuber CLA 2008-08-14 04:56:34 EDT
I changed the Summary, previous value was:
HostShellProcessAdapter.destroy() does not follow semantics of Process.destroy()

because the issue is dstore specific: looking at SshHostShell, for instance, you'll see that calling its #exit() method does forcefully close the Streams and thus terminate the shell synchronously as you expect. Arguably, exact API specification of IHostShell#exit() behavior is not yet documented, and I just filed bug 244130 to get this done.

Looking at DStoreShellThread and CommandMinerThread, I think it should work for now if you send the command "#break" in order to send a break signal that should kill your child process. Let me know if this works for you, then we can rev down severity and think about sending a #break in DStoreHostShell's exit() method automatically in order to make behavior of the various IHostShell implementations work the same.

The HostShellProcessAdapter does work as expected IMHO, assuming that IHostShell#exit() must terminate child processes.

Yet another aspect of this bug is that when we launch something from a Shell, we currently have no chance getting the PID of the launched process in a Platform independent manner, such that we could use the IProcessService to actually kill the process. Bug 161774 has been open for a long time to investigate this.

Your input and, in the ideal case, a patch would be highly appreciated for fixing this since you obviously have an environment to work on this.
Comment 2 Martin Oberhuber CLA 2008-08-14 05:20:48 EDT
Yet another aspect of this is the need for public API to send signals to IHostShell instances. I filed bug 244132 to track this.
Comment 3 Martin Oberhuber CLA 2008-11-12 08:38:48 EST
I'm inclined to rev down severity since my questions from comment 1 were not answered, specifically whether sending the command "#break" helps. I'm not sure who can work on this without your help. The hints should be sufficient to come up with a patch.
Comment 4 Chris Recoskie CLA 2008-11-13 14:04:51 EST
(In reply to comment #3)
> I'm inclined to rev down severity since my questions from comment 1 were not
> answered, specifically whether sending the command "#break" helps. I'm not sure
> who can work on this without your help. The hints should be sufficient to come
> up with a patch.

Well, we've been busy getting RDT out the door, and now am on a long overdue vacation, so I haven't had time to try this yet.  I will take a look at some point after I'm back.
Comment 5 Chris Recoskie CLA 2008-11-17 13:40:29 EST
(In reply to comment #3)
> I'm inclined to rev down severity since my questions from comment 1 were not
> answered, specifically whether sending the command "#break" helps. I'm not sure
> who can work on this without your help. The hints should be sufficient to come
> up with a patch.

I tried sending the "#break" in DStoreHostShell.exit(), but it had no effect.  I assume you meant to literally send those characters and that you did not mean some shorthand for CTRL + BREAK.
Comment 6 Martin Oberhuber CLA 2008-11-21 06:57:50 EST
Chris - as per bug 153275 comment 1 it looks like you might need a PTY on the remote to be able and respond to the #break command. The PTY is only IBM closed source for now. Bug 196337 has some PTY code attached under EPL, but I'm not sure if that will work here.

Dave M, do you have an idea how dstore could forcefully terminate child processes on IHostShell#exit() ? -- Since the dstore miner is getting a Process object back from the Runtime.exec() command it should work to just Process.destroy() when an exit command is received?
Comment 7 David McKnight CLA 2009-02-03 14:28:20 EST
Created attachment 124595 [details]
patch to issue cancel command on DStoreHostShell.exist()
Comment 8 David McKnight CLA 2009-02-03 14:30:03 EST
(In reply to comment #6)
> Chris - as per bug 153275 comment 1 it looks like you might need a PTY on the
> remote to be able and respond to the #break command. The PTY is only IBM closed
> source for now. Bug 196337 has some PTY code attached under EPL, but I'm not
> sure if that will work here.
> 
> Dave M, do you have an idea how dstore could forcefully terminate child
> processes on IHostShell#exit() ? -- Since the dstore miner is getting a Process
> object back from the Runtime.exec() command it should work to just
> Process.destroy() when an exit command is received?
> 

With the patch I just attached, we issue a cancel command instead of writing "exit".  On the server side this first issues an "exit" but if that fails, it falls back to a Process.destroy().  Does this help?
Comment 9 Chris Recoskie CLA 2009-02-03 15:38:53 EST
(In reply to comment #8)
> With the patch I just attached, we issue a cancel command instead of writing
> "exit".  On the server side this first issues an "exit" but if that fails, it
> falls back to a Process.destroy().  Does this help?

Works :-)
Comment 10 David McKnight CLA 2009-02-03 17:13:47 EST
I've committed the change to cvs.
Comment 11 Chris Recoskie CLA 2009-02-04 08:28:37 EST
Is there any chance of this being backported to 3.0.3?  Although 3.1 seems so far compatible with Eclipse 3.4, it is a long time until June and I would really like it if our users could cancel builds before then (see bug 250319).
Comment 12 David McKnight CLA 2009-02-04 12:48:29 EST
(In reply to comment #11)
> Is there any chance of this being backported to 3.0.3?  Although 3.1 seems so
> far compatible with Eclipse 3.4, it is a long time until June and I would
> really like it if our users could cancel builds before then (see bug 250319).
> 

I've opened bug 250319 for the backport to 3.0.3.
Comment 13 Chris Recoskie CLA 2009-02-04 12:59:56 EST
(In reply to comment #12)
> I've opened bug 250319 for the backport to 3.0.3.

I think you mean bug 263669
Comment 14 David McKnight CLA 2009-02-04 13:31:32 EST
(In reply to comment #13)
> (In reply to comment #12)
> > I've opened bug 250319 for the backport to 3.0.3.
> 
> I think you mean bug 263669
> 

Oh right, that's what I meant.