Skip to content

Commit

Permalink
Abolish SIGCONT trap on UNIX-like
Browse files Browse the repository at this point in the history
Shouldn't change SIGCONT behavior on UNIX-like for backward compatibility.
The rpc dump command is a new function, so make it send SIGCONT to all fluentd
processes.

With `SIGDUMP_PATH` environment variable specified on UNIX-like,
the rpc dump command will cause a writing conflict.
This should be fixed by improving the Sigdump library so that we can
specify a directory path.

Signed-off-by: Daijiro Fukuda <fukuda@clear-code.com>
  • Loading branch information
daipom committed Mar 23, 2022
1 parent eac5ce1 commit 9d0d1f3
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions lib/fluent/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ def run_rpc_server
@rpc_server.mount_proc('/api/processes.dump') { |req, res|
$log.debug "fluentd RPC got /api/processes.dump request"
if Fluent.windows?
supervisor_dump_handler
supervisor_dump_handler_for_windows
else
Process.kill :CONT, $$
send_signal_to_workers(:CONT)
end
nil
}
Expand Down Expand Up @@ -196,11 +197,6 @@ def install_supervisor_signal_handlers
$log.debug 'fluentd supervisor process got SIGUSR2'
supervisor_sigusr2_handler
end

trap :CONT do
$log.debug 'fluentd supervisor process got CONT'
supervisor_dump_handler
end
end

if Fluent.windows?
Expand Down Expand Up @@ -267,7 +263,7 @@ def install_windows_event_handler
when :usr2
supervisor_sigusr2_handler
when :cont
supervisor_dump_handler
supervisor_dump_handler_for_windows
when :stop_event_thread
break
end
Expand Down Expand Up @@ -323,20 +319,14 @@ def supervisor_sigusr2_handler
$log.error "Failed to reload config file: #{e}"
end

def supervisor_dump_handler
if Fluent.windows?
FluentSigdump.dump_windows
else
# Need new thread to dump in UNIX-like.
# (For some reason it seems to work fine on Windows with the original thread.)
Thread.new do
# As for UNIX-like, `kill CONT` signal is trapped by the supervisor process,
# so we have to dump manually for the supervisor process.
# (Normally, the dump is automatic with the signal by using `require 'sigdump/setup'`.)
require 'sigdump'
Sigdump.dump
end
end
def supervisor_dump_handler_for_windows
# As for UNIX-like, SIGCONT signal to each process makes the process output its dump-file,
# and it is implemented before the implementation of the function for Windows.
# It is possible to trap SIGCONT and handle it here also on UNIX-like,
# but for backward compatibility, this handler is currently for a Windows-only.
raise "[BUG] This function is for Windows ONLY." unless Fluent.windows?

FluentSigdump.dump_windows

send_signal_to_workers(:CONT)
rescue => e
Expand Down

0 comments on commit 9d0d1f3

Please sign in to comment.