Improve registering signal handlers in java.lang.Terminator.setup()
neil.richards at ngmr.net
Tue Aug 7 18:07:07 UTC 2012
On Tue, 2012-08-07 at 18:01 +0100, Alan Bateman wrote:
> On 07/08/2012 15:02, Neil Richards wrote:
> > :
> > > From a Java Class Library point of view, it seems to me that the desire
> > is to register shutdown hooks for any of these signals (HUP, INT and
> > TERM) whose use has not been restricted by the VM.
> > So an attempt to register for each of these signals should be made,
> > independent of the result of any of the other attempts.
> > To do anything else builds into the Java class library code assumptions
> > about the behaviour of the VM which are inherently implementation
> > (version?) specific, which is a brittle thing to do.
> > It currently assumes that the VM will either have restricted all these
> > signals (the -Xrs case) or none of them.
> > This assumption holds true for the current version of Hotspot VM, but
> > not necessarily for other VM implementations, whose mix of signal usage
> > may differ.
> > So I think Frank's suggested change helps this code to adhere the VM /
> > Class Library interface boundary, and so makes it less brittle.
> As David said, the proposed change is harmless and I don't think anyone
> has any issue with it. It's really just us trying to understand whether
> there is really an issue here or not as it is has not been clear from
> the mails so far. I'm guessing it's AIX or J9 where -Xrs may be mapped
> to a different set of signals. FWIW, the termination setup has not been
> touched in >10 years. Looking at it now then it could have been done in
> other ways that wouldn't have been VM specific. Whether it's worth doing
> this now isn't clear as it just hasn't been an issue (to my knowledge
Digging back into its history, I see that it all stems from running java
under 'nohup' (e.g. 'nohup java ProgramWithShutdownHooks &').
'nohup' prevents things being registered against SIGHUP, so trying to do
so causes an exception to be thrown.
When this happens, the Terminator code currently decides that it
shouldn't bother trying to register shutdown hooks for SIGINT or SIGTERM
The result is that shutdown hooks aren't currently run when a java
process run using 'nohup' is sent a SIGINT or SIGTERM signal, because of
the code's (false) assumption that a failure to register a handler for
SIGHUP must mean that the VM is running in -Xrs mode.
I don't think the current observed behaviour in this scenario is either
expected or desirable.
It occurs for both J9 and Hotspot (at least, on my Ubuntu box, bash
Hope this helps to clarify the scenario.
Unless stated above:
IBM email: neil_richards at uk.ibm.com
IBM United Kingdom Limited - Registered in England and Wales with number 741598.
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU
More information about the core-libs-dev