Skip to content

Commit

Permalink
Merge pull request #1957 from abicky/resolve-unexpected-exist-on-sigusr1
Browse files Browse the repository at this point in the history
Resolve unexpected exit on SIGUSR1
  • Loading branch information
repeatedly authored Apr 27, 2018
2 parents ee4a192 + 52a45e2 commit 5898965
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
7 changes: 7 additions & 0 deletions lib/fluent/log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -625,5 +625,12 @@ def sync=(v)
super
end
end

def reopen(path, mode)
if mode != 'a'
raise "Unsupported mode: #{mode}"
end
super(path)
end
end
end
13 changes: 8 additions & 5 deletions lib/fluent/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ def supervisor_sighup_handler

def supervisor_sigusr1_handler
if log = config[:logger_initializer]
log.reopen!
# Creating new thread due to mutex can't lock
# in main thread during trap context
Thread.new {
log.reopen!
}.run
end

if config[:worker_pid]
Expand Down Expand Up @@ -685,14 +689,13 @@ def install_main_process_signal_handlers
end

def flush_buffer
$log.debug "fluentd main process get SIGUSR1"
$log.info "force flushing buffered events"
@log.reopen!

# Creating new thread due to mutex can't lock
# in main thread during trap context
Thread.new {
begin
$log.debug "fluentd main process get SIGUSR1"
$log.info "force flushing buffered events"
@log.reopen!
Fluent::Engine.flush!
$log.debug "flushing thread: flushed"
rescue Exception => e
Expand Down

0 comments on commit 5898965

Please sign in to comment.