Skip to content
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

Option to turn off SIGUSR2 trapping #3570

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Option to turn off SIGUSR2 trapping
This option is necessary for compatibility with Java Flight Recorder,
a performance monitoring and diagnostic tool used with JRuby and
TruffleRuby.
  • Loading branch information
mohamedhafez committed Dec 16, 2024
commit 2aa20b984187f0e60b861a659d722a748a870535
6 changes: 6 additions & 0 deletions docs/java_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Moreover, default values may be used in case of invalid inputs.
| PUMA_QUERY_STRING_MAX_LENGTH | 1024 * 10 | Positive natural number |
| PUMA_REQUEST_PATH_MAX_LENGTH | 8192 | Positive natural number |
| PUMA_REQUEST_URI_MAX_LENGTH | 1024 * 12 | Positive natural number |
| PUMA_SKIP_SIGUSR2 | nil | n/a |

## Examples

Expand Down Expand Up @@ -46,3 +47,8 @@ foo@bar:~ curl "http://localhost:9292${path}"
Hello World
```

### Java Flight Recorder Compatibility

Unfortunately Java Flight Recorder uses `SIGUSR2` internally. If you wish to
use JFR, turn off Puma's trapping of `SIGUSR2` by setting the environment variable
`PUMA_SKIP_SIGUSR2` to any value.
12 changes: 7 additions & 5 deletions lib/puma/launcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,14 @@ def generate_restart_data
end

def setup_signals
begin
Signal.trap "SIGUSR2" do
restart
unless ENV["PUMA_SKIP_SIGUSR2"]
begin
Signal.trap "SIGUSR2" do
restart
end
rescue Exception
log "*** SIGUSR2 not implemented, signal based restart unavailable!"
end
rescue Exception
log "*** SIGUSR2 not implemented, signal based restart unavailable!"
end

unless Puma.jruby?
Expand Down
33 changes: 33 additions & 0 deletions test/test_skip_sigusr2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

require_relative "helper"
require_relative "helpers/integration"

require "puma/plugin"

class TestSkipSigusr2 < TestIntegration

def setup
skip_unless_signal_exist? :TERM
skip_unless_signal_exist? :USR2

super
end

def teardown
super unless skipped?
end

def test_sigusr2_handler_not_installed
cli_server "test/rackup/hello.ru",
env: { 'PUMA_SKIP_SIGUSR2' => 'true' }, config: <<~CONFIG
app do |_|
[200, {}, [Signal.trap('SIGUSR2', 'IGNORE').to_s]]
end
CONFIG

assert_equal 'DEFAULT', read_body(connect)

stop_server
end
end
Loading