System.exit deadlock if called within a hook
David Lloyd
david.lloyd at redhat.com
Mon Apr 25 15:29:28 UTC 2022
On Mon, Apr 25, 2022 at 9:25 AM <remi.catherinot at orange.com> wrote:
>
> Ok, you're right that it can raise an exception when the calling thread does not have the security privileges needed. But what if it had them ? Right now the deadlock comes from the fact is doesn't got back to the caller with an exception and doesn't end the current thread. My 1st proposal was to have a way to end the current thread. If you think that is not acceptable and prefer the exception solution, then something like throw new IllegalStateException("Shutdown in progress") which is already used when adding new hooks while shutting down and adjust the System.exit method documentation accordingly (might be dangerous since it "breaks" actual documented and implemented contract, might be too heavy for a change).
>
> First things first : do you think this is an issue the JVM has to solve (either using a destroy-current-thread solution, or a throw-IllegalStateException one), or do you think this was a hook misuse and maybe would only need maybe a clearer warning in the hooks's documentation, or do you think we keep everything as it is because I should have guessed better reading the actual documentation ?
If you're asking me personally, I think it would make a lot of sense
to throw IllegalStateException or a new subclass thereof (e.g.
`ExitInProgressException` or something). However, my opinion doesn't
count. I suspect that those whose opinions *do* count will probably
say that this would be too much of a breaking change.
--
- DML • he/him
More information about the core-libs-dev
mailing list