-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Improve handling of SIGCONT after SIGTERM #4034
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,6 +190,12 @@ def install_supervisor_signal_handlers | |
$log.debug 'fluentd supervisor process got SIGUSR2' | ||
supervisor_sigusr2_handler | ||
end | ||
|
||
term_handler = trap :TERM do | ||
# After SIGTERM, disable the sigdump file by ignoring SIGCONT. | ||
trap(:CONT, nil) | ||
term_handler.call | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it safer to consider the possibility that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see! This can be https://docs.ruby-lang.org/ja/latest/method/Signal/m/trap.html
So this looks good! |
||
end | ||
end | ||
|
||
if Fluent.windows? | ||
|
@@ -922,6 +928,9 @@ def install_main_process_signal_handlers | |
end | ||
|
||
trap :TERM do | ||
# After SIGTERM, disable the sigdump file by ignoring SIGCONT. | ||
trap(:CONT, nil) | ||
|
||
$log.debug "fluentd main process get SIGTERM" | ||
unless @finished | ||
@finished = true | ||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -32,6 +32,7 @@ def setup | |||||||||
@tmp_dir = tmp_dir | ||||||||||
@tmp_root_dir = File.join(@tmp_dir, 'root') | ||||||||||
FileUtils.mkdir_p(@tmp_dir) | ||||||||||
@sigdump_path = "/tmp/sigdump-#{$$}.log" | ||||||||||
end | ||||||||||
|
||||||||||
def teardown | ||||||||||
|
@@ -191,7 +192,7 @@ def test_system_config | |||||||||
end | ||||||||||
end | ||||||||||
|
||||||||||
def test_main_process_signal_handlers | ||||||||||
def test_usr1_in_main_process_signal_handlers | ||||||||||
omit "Windows cannot handle signals" if Fluent.windows? | ||||||||||
|
||||||||||
create_info_dummy_logger | ||||||||||
|
@@ -213,6 +214,52 @@ def test_main_process_signal_handlers | |||||||||
$log.out.reset if $log && $log.out && $log.out.respond_to?(:reset) | ||||||||||
end | ||||||||||
|
||||||||||
def test_cont_in_main_processsignal_handlers | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
omit "Windows cannot handle signals" if Fluent.windows? | ||||||||||
|
||||||||||
opts = Fluent::Supervisor.default_options | ||||||||||
sv = Fluent::Supervisor.new(opts) | ||||||||||
sv.send(:install_main_process_signal_handlers) | ||||||||||
|
||||||||||
begin | ||||||||||
Process.kill :CONT, $$ | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
rescue | ||||||||||
end | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we remove this |
||||||||||
|
||||||||||
sleep 1 | ||||||||||
|
||||||||||
assert_true File.exist?(@sigdump_path) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Power assert style is preferred for better failure message:
Suggested change
|
||||||||||
ensure | ||||||||||
File.delete(@sigdump_path) if File.exist?(@sigdump_path) | ||||||||||
end | ||||||||||
|
||||||||||
def test_term_cont_in_main_processsignal_handlers | ||||||||||
omit "Windows cannot handle signals" if Fluent.windows? | ||||||||||
|
||||||||||
create_debug_dummy_logger | ||||||||||
|
||||||||||
opts = Fluent::Supervisor.default_options | ||||||||||
sv = Fluent::Supervisor.new(opts) | ||||||||||
sv.send(:install_main_process_signal_handlers) | ||||||||||
|
||||||||||
begin | ||||||||||
Process.kill :TERM, $$ | ||||||||||
Process.kill :CONT, $$ | ||||||||||
rescue | ||||||||||
end | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we remove this |
||||||||||
|
||||||||||
sleep 1 | ||||||||||
|
||||||||||
debug_msg = '[debug]: fluentd main process get SIGTERM' + "\n" | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
logs = $log.out.logs | ||||||||||
assert{ logs.any?{|log| log.include?(debug_msg) } } | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems to be the same code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, sorry. This is garbage. |
||||||||||
|
||||||||||
assert_false File.exist?(@sigdump_path) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
ensure | ||||||||||
$log.out.reset if $log && $log.out && $log.out.respond_to?(:reset) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
File.delete(@sigdump_path) if File.exist?(@sigdump_path) | ||||||||||
end | ||||||||||
|
||||||||||
def test_main_process_command_handlers | ||||||||||
omit "Only for Windows, alternative to UNIX signals" unless Fluent.windows? | ||||||||||
|
||||||||||
|
@@ -239,7 +286,7 @@ def test_main_process_command_handlers | |||||||||
$log.out.reset if $log && $log.out && $log.out.respond_to?(:reset) | ||||||||||
end | ||||||||||
|
||||||||||
def test_supervisor_signal_handler | ||||||||||
def test_usr1_in_supervisor_signal_handler | ||||||||||
omit "Windows cannot handle signals" if Fluent.windows? | ||||||||||
|
||||||||||
create_debug_dummy_logger | ||||||||||
|
@@ -260,6 +307,43 @@ def test_supervisor_signal_handler | |||||||||
$log.out.reset if $log && $log.out && $log.out.respond_to?(:reset) | ||||||||||
end | ||||||||||
|
||||||||||
def test_cont_in_supervisor_signal_handler | ||||||||||
omit "Windows cannot handle signals" if Fluent.windows? | ||||||||||
|
||||||||||
server = DummyServer.new | ||||||||||
server.install_supervisor_signal_handlers | ||||||||||
begin | ||||||||||
Process.kill :CONT, $$ | ||||||||||
rescue | ||||||||||
end | ||||||||||
|
||||||||||
sleep 1 | ||||||||||
|
||||||||||
assert_true File.exist?(@sigdump_path) | ||||||||||
ensure | ||||||||||
File.delete(@sigdump_path) if File.exist?(@sigdump_path) | ||||||||||
end | ||||||||||
|
||||||||||
# TODO Sending SIGTERM terminates the test itself. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, it seems to depend on the order of the test execution. I haven't been able to check it clearly, but it looks like the proc obj of We may need some measures for this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right. I was mistaken. |
||||||||||
# I think we have to figure out a good way. | ||||||||||
# def test_term_cont_in_supervisor_signal_handler | ||||||||||
# omit "Windows cannot handle signals" if Fluent.windows? | ||||||||||
# | ||||||||||
# server = DummyServer.new | ||||||||||
# server.install_supervisor_signal_handlers | ||||||||||
# begin | ||||||||||
# Process.kill :TERM, $$ | ||||||||||
# Process.kill :CONT, $$ | ||||||||||
# rescue | ||||||||||
# end | ||||||||||
# | ||||||||||
# sleep 1 | ||||||||||
# | ||||||||||
# assert_not File.exist?(@sigdump_path) | ||||||||||
# ensure | ||||||||||
# File.delete(@sigdump_path) if File.exist?(@sigdump_path) | ||||||||||
# end | ||||||||||
|
||||||||||
def test_windows_shutdown_event | ||||||||||
omit "Only for Windows platform" unless Fluent.windows? | ||||||||||
|
||||||||||
|
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.
This
term_handler.call()
will callServer.stop()
in ServerEngine.I think this is a nice way.