-
Notifications
You must be signed in to change notification settings - Fork 914
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Push signal traps and at_exit blocks to a common thread for exec. #5441
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
heh :) ... is this an arbitrary 1h?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.