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

Windows: Fix an issue where stopping the service immediately after startup could leave the processes #4782

Merged
merged 3 commits into from
Jan 28, 2025
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 initialization 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
Loading