Skip to content

Commit

Permalink
winsvc: retry stop event
Browse files Browse the repository at this point in the history
Signed-off-by: Daijiro Fukuda <fukuda@clear-code.com>
  • Loading branch information
daipom committed Jan 27, 2025
1 parent 30c3ce0 commit e1b87ca
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions lib/fluent/winsvc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@ def service_main
end

def service_stop
set_event(@service_name)
if @pid > 0
Process.waitpid(@pid)
if @pid <= 0
set_event(@service_name)
return
end

repeat_set_event_several_times_until_success(@service_name)
Process.waitpid(@pid)
end

def service_paramchange
Expand All @@ -91,6 +94,24 @@ def set_event(event_name)
ev.set
ev.close
end

def repeat_set_event_several_times_until_success(event_name)
retries = 0
max_retries = 10
delay_sec = 3

begin
set_event(event_name)
rescue Errno::ENOENT
# This error occurs when the supervisor process has not yet created the event.
# If STOP is immediately executed, this state will occur.
# Retry `set_event' to wait for the initilization of the supervisor.
retries += 1
raise if max_retries < retries
sleep(delay_sec)
retry
end
end
end

FluentdService.new(opts[:service_name]).mainloop
Expand Down

0 comments on commit e1b87ca

Please sign in to comment.