Push signal traps and at_exit blocks to a common thread for exec.#5441
Push signal traps and at_exit blocks to a common thread for exec.#5441enebo merged 2 commits intojruby:masterfrom
Conversation
This avoids races due to the signal traps running on the JVM's signal-handling thread while we run at_exit blocks on JRuby's main thread. Fixes jruby#5437.
|
@Adithya-copart Can you provide an example script that causes a race and verify that this PR fixes it? |
|
@headius Will the code in the first comment of puma/puma#1675 work? Steps: There is a race between the I can recreate something later today if it doesn't. Thanks! EDIT: Added the code. |
|
@Adithya-copart Ah yes, that's quite similar to how this PR works, except that we use a JDK "ExecutorService" that manages the native thread and queueing for us. I will try to reproduce based on your instructions. There are failures in CI, unfortunately. It seems that at least the CRuby/MRI tests expect I'm not sure we want to emulate that behavior. I have a thought for a modification to my fix that just waits for all scheduled signal handlers to execute before proceeding on to the |
| try { | ||
| executor.shutdown(); | ||
| if (!executor.awaitTermination(1, TimeUnit.HOURS)) { | ||
| throw newRuntimeError("failed to execute at_exit blocks within 1h timeout"); |
There was a problem hiding this comment.
heh :) ... is this an arbitrary 1h?
There was a problem hiding this comment.
I thought about it for at least 30 seconds. But yeah it's pretty much arbitrary.
|
This had to be reverted due to some unexpected behavior changes in at_exit. See #5437 (comment). |
This avoids races due to the signal traps running on the JVM's
signal-handling thread while we run at_exit blocks on JRuby's
main thread.
Fixes #5437.