You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Question: Is replacing SIGTERM/SIGINT handlers with exit(0) on require intentional? #253
Because this happens whenever the gem is loaded—even in apps using a shared Gemfile with mysql2—processes without their own signal handlers (rails runner, Rake tasks, cron/batch jobs) are affected:
Processes stopped with Ctrl-C (SIGINT) or SIGTERM exit with status 0, reporting interrupted jobs as successful.
Previously registered signal handlers are replaced rather than chained.
rescue Interrupt no longer catches Ctrl-C.
Could you help clarify a few questions about this behavior?
Is the current behavior (exiting with status 0 and replacing existing TERM/INT handlers) intentional?
Since cleanup appears to run in at_exit, are these signal handlers still needed for specific environments or edge cases?
In the meantime, is it safe for applications to restore the default handlers right after the gem is loaded (Signal.trap("TERM", "DEFAULT") and Signal.trap("INT", "DEFAULT")), and will the wrapper still shut down cleanly?
Expected Behavior
Requiring the gem preserves the process's existing signal handling, allowing cleanup hooks (ensure/at_exit) to run while exiting with a non-zero status (130 for SIGINT, 143 for SIGTERM) and keeping existing handlers intact.
Current Behavior
An interrupted process exits with status 0 without raising Interrupt.
Reproduction Steps
In a Rails app with gem "aws_advanced_ruby_driver_wrapper" in its Gemfile:
bin/rails runner 'sleep'# press Ctrl-C after the app has bootedecho$?# => 0 (expected 130)
bin/rails runner 'sleep'& pid=$!
sleep 10 # wait for the app to bootkill -TERM "$pid";wait"$pid"echo$?# => 0 (expected 143)
Hi @yayamochi, thanks for the detailed report and reproduction steps - we were able to reproduce this on our side. Answers to your questions:
1. Is the current behavior intentional?
No, this is a bug. The wrapper has registered these TERM/INT traps since its first release so that its background resources are cleaned up on shutdown, but we did not realize that calling exit(0) from them also causes the negative side effects you mentioned.
2. Are these signal handlers still needed?
No. Ruby's default handlers already raise Interrupt (for SIGINT) or SignalException (for SIGTERM) in the main thread, which unwinds the stack, runs ensure blocks, and then runs at_exit hooks, including the wrapper's shutdown. We were not aware at the time that the signal handlers were unnecessary.
3. Is it safe to restore the default handlers after the gem is loaded?
Yes. We verified that after restoring the defaults, rescue Interrupt and ensure behave normally, the wrapper's at_exit shutdown still runs, and the process exits with 130 for SIGINT and 143 for SIGTERM. A couple of notes:
The restore needs to run after the gem is required, for example right after Bundler.require in config/application.rb:
If your application or a library installed its own TERM/INT handlers before the gem was loaded, re-install those instead of "DEFAULT", since the wrapper's handlers will have replaced them.
We're treating this as a bug and will look into removing these signal handlers so that requiring the gem no longer changes the process's signal handling. We'll update this issue once a fix is available.
@sophia-bq@aaron-congo
Thanks for the quick investigation and clear answers!
Sounds good, I'll use this approach as a temporary workaround for now.
Looking forward to the fix—thanks again!
Thanks for confirming the bug. Two more places our initial testing found while trying to adopt the gem
Shoryuken: Shoryuken::Runner#run installs its INT and TERM handlers first and loads the application afterwards (Rails, or the files passed with -r), and nothing re-installs them, so the wrapper's handler replaces them. Both signals pointed at aws_advanced_ruby_driver_wrapper.rb:120 instead of shoryuken/runner.rb. SIGTERM then exits at once instead of running Shoryuken's graceful shutdown, and in-flight messages wait out their visibility timeout. Restoring "DEFAULT" does not help here, because Shoryuken needs its own handler back.
Container tasks: A rake task or rails runner that ECS stops with SIGTERM exits 0, so the stopped task reports exit code 0 as if it had succeeded.
Thank you for raising these additional concerns! We believe we have addressed the underlying cause in #257 which has been merged and should be available in our next release. If you have any comments on the PR or concerns this will not solve your issues feel free to let us know.
We'll make sure to update this ticket when the next release is out.
I can confirm the Shoryuken part of the earlier comment is accurate. shoryuken start sets up its signal handlers first and then loads the app. With 1.1.0, the wrapper replaces the INT and TERM handlers while the app loads, so Shoryuken's graceful shutdown never runs on TERM. As noted, Signal.trap("TERM", "DEFAULT") doesn't help under Shoryuken, because Shoryuken needs its own handler back.
On the Shoryuken side, we're adding a safeguard so this can't happen with any gem: after loading the app, Shoryuken puts its handlers back and logs a warning naming the file that replaced them. It'll ship in the next Shoryuken release.
Activity
sophia-bq commentedon Nov 25, 2026
Hi @yayamochi ,
Thanks for reaching out and raising this issue.
We're taking a look at your questions and will update you once we verify our answers.
Thank you for your patience!
aaron-congo commentedon Nov 27, 2026
Hi @yayamochi, thanks for the detailed report and reproduction steps - we were able to reproduce this on our side. Answers to your questions:
1. Is the current behavior intentional?
No, this is a bug. The wrapper has registered these
TERM/INTtraps since its first release so that its background resources are cleaned up on shutdown, but we did not realize that callingexit(0)from them also causes the negative side effects you mentioned.2. Are these signal handlers still needed?
No. Ruby's default handlers already raise
Interrupt(forSIGINT) orSignalException(forSIGTERM) in the main thread, which unwinds the stack, runsensureblocks, and then runsat_exithooks, including the wrapper's shutdown. We were not aware at the time that the signal handlers were unnecessary.3. Is it safe to restore the default handlers after the gem is loaded?
Yes. We verified that after restoring the defaults,
rescue Interruptandensurebehave normally, the wrapper'sat_exitshutdown still runs, and the process exits with130forSIGINTand143forSIGTERM. A couple of notes:The restore needs to run after the gem is required, for example right after
Bundler.requireinconfig/application.rb:If your application or a library installed its own
TERM/INThandlers before the gem was loaded, re-install those instead of"DEFAULT", since the wrapper's handlers will have replaced them.We're treating this as a bug and will look into removing these signal handlers so that requiring the gem no longer changes the process's signal handling. We'll update this issue once a fix is available.
Thanks again for raising this!
yayamochi commentedon Nov 30, 2026
@sophia-bq @aaron-congo
Thanks for the quick investigation and clear answers!
Sounds good, I'll use this approach as a temporary workaround for now.
Looking forward to the fix—thanks again!
lgeorge-1l commentedon Dec 1, 2026
Thanks for confirming the bug. Two more places our initial testing found while trying to adopt the gem
Shoryuken:
Shoryuken::Runner#runinstalls its INT and TERM handlers first and loads the application afterwards (Rails, or the files passed with -r), and nothing re-installs them, so the wrapper's handler replaces them. Both signals pointed ataws_advanced_ruby_driver_wrapper.rb:120instead ofshoryuken/runner.rb. SIGTERM then exits at once instead of running Shoryuken's graceful shutdown, and in-flight messages wait out their visibility timeout. Restoring "DEFAULT" does not help here, because Shoryuken needs its own handler back.Container tasks: A rake task or rails runner that ECS stops with SIGTERM exits 0, so the stopped task reports exit code 0 as if it had succeeded.
sophia-bq commentedon Dec 2, 2026
Hi @lgeorge-1l ,
Thank you for raising these additional concerns! We believe we have addressed the underlying cause in #257 which has been merged and should be available in our next release. If you have any comments on the PR or concerns this will not solve your issues feel free to let us know.
We'll make sure to update this ticket when the next release is out.
mensfeld commentedon Dec 3, 2026
Shoryuken maintainer here.
I can confirm the Shoryuken part of the earlier comment is accurate. shoryuken start sets up its signal handlers first and then loads the app. With 1.1.0, the wrapper replaces the INT and TERM handlers while the app loads, so Shoryuken's graceful shutdown never runs on TERM. As noted, Signal.trap("TERM", "DEFAULT") doesn't help under Shoryuken, because Shoryuken needs its own handler back.
On the Shoryuken side, we're adding a safeguard so this can't happen with any gem: after loading the app, Shoryuken puts its handlers back and logs a warning naming the file that replaced them. It'll ship in the next Shoryuken release.
ref ruby-shoryuken/shoryuken#1226