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

Don't persist before_fork hook in state file #846

Merged
merged 1 commit into from Jan 15, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/puma/cli.rb
Expand Up @@ -25,6 +25,12 @@ class << self
# Handles invoke a Puma::Server in a command line style.
#
class CLI
KEYS_NOT_TO_PERSIST_IN_STATE = [
:logger, :lowlevel_error_handler,
:before_worker_shutdown, :before_worker_boot, :before_worker_fork,
:after_worker_boot, :before_fork, :on_restart
]

# Create a new CLI object using +argv+ as the command line
# arguments.
#
Expand Down Expand Up @@ -108,12 +114,7 @@ def write_state
state = { 'pid' => Process.pid }
cfg = @config.dup

[
:logger,
:before_worker_shutdown, :before_worker_boot, :before_worker_fork,
:after_worker_boot,
:on_restart, :lowlevel_error_handler
].each { |k| cfg.options.delete(k) }
KEYS_NOT_TO_PERSIST_IN_STATE.each { |k| cfg.options.delete(k) }
state['config'] = cfg

require 'yaml'
Expand Down
14 changes: 14 additions & 0 deletions test/config/state_file_testing_config.rb
@@ -0,0 +1,14 @@
pidfile "t3-pid"
workers 3
on_worker_boot do |index|
File.open("t3-worker-#{index}-pid", "w") { |f| f.puts Process.pid }
end

before_fork { 1 }
on_worker_shutdown { 1 }
on_worker_boot { 1 }
on_worker_fork { 1 }
on_restart { 1 }
after_worker_boot { 1 }
lowlevel_error_handler { 1 }

15 changes: 15 additions & 0 deletions test/test_cli.rb
Expand Up @@ -147,6 +147,21 @@ def test_state
assert_equal url, data["config"].options[:control_url]
end

def test_state_file_callback_filtering
cli = Puma::CLI.new [ "--config", "test/config/state_file_testing_config.rb",
"--state", @tmp_path ]
cli.send( :parse_options )
cli.write_state

data = nil
assert_nothing_raised do
data = YAML.load_file( @tmp_path )
end

keys_not_stripped = data.keys & Puma::CLI::KEYS_NOT_TO_PERSIST_IN_STATE
assert_empty keys_not_stripped
end

def test_load_path
cli = Puma::CLI.new ["--include", 'foo/bar']
cli.send(:parse_options)
Expand Down