-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
trigger input plugin shutdown using out of band call #3812
Changes from all commits
2be4a20
365c56e
09665ee
41cd880
79d822a
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 |
---|---|---|
|
@@ -175,9 +175,16 @@ def inputworker(plugin) | |
LogStash::Util::set_thread_name("<#{plugin.class.config_name}") | ||
begin | ||
plugin.run(@input_to_filter) | ||
rescue LogStash::ShutdownSignal | ||
# ignore and quit | ||
rescue => e | ||
# if plugin is stopping, ignore uncatched exceptions and exit worker | ||
if plugin.stop? | ||
@logger.debug("Input plugin raised exception during shutdown, ignoring it.", | ||
:plugin => plugin.class.config_name, :exception => e, | ||
:backtrace => e.backtrace) | ||
return | ||
end | ||
|
||
# otherwise, report error and restart | ||
if @logger.debug? | ||
@logger.error(I18n.t("logstash.pipeline.worker-error-debug", | ||
:plugin => plugin.inspect, :error => e.to_s, | ||
|
@@ -187,23 +194,13 @@ def inputworker(plugin) | |
@logger.error(I18n.t("logstash.pipeline.worker-error", | ||
:plugin => plugin.inspect, :error => e)) | ||
end | ||
puts e.backtrace if @logger.debug? | ||
# input teardown must be synchronized since is can be called concurrently by | ||
# the input worker thread and from the pipeline thread shutdown method. | ||
# this means that input teardown methods must support multiple calls. | ||
@run_mutex.synchronize{plugin.teardown} | ||
sleep 1 | ||
retry | ||
end | ||
ensure | ||
begin | ||
# input teardown must be synchronized since is can be called concurrently by | ||
# the input worker thread and from the pipeline thread shutdown method. | ||
# this means that input teardown methods must support multiple calls. | ||
@run_mutex.synchronize{plugin.teardown} | ||
rescue LogStash::ShutdownSignal | ||
# teardown could receive the ShutdownSignal, retry it | ||
|
||
# Assuming the failure that caused this exception is transient, | ||
# let's sleep for a bit and execute #run again | ||
sleep(1) | ||
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 know the previous code's sleep() didn't have a comment, but let's make a comment here explaining why we are sleeping. |
||
retry | ||
ensure | ||
plugin.teardown | ||
end | ||
end # def inputworker | ||
|
||
|
@@ -242,8 +239,8 @@ def outputworker | |
event = @filter_to_output.pop | ||
break if event == LogStash::SHUTDOWN | ||
output_func(event) | ||
end # while true | ||
|
||
end | ||
ensure | ||
@outputs.each do |output| | ||
output.worker_plugins.each(&:teardown) | ||
end | ||
|
@@ -255,37 +252,19 @@ def outputworker | |
def shutdown | ||
InflightEventsReporter.logger = @logger | ||
InflightEventsReporter.start(@input_to_filter, @filter_to_output, @outputs) | ||
@input_threads.each do |thread| | ||
# Interrupt all inputs | ||
@logger.info("Sending shutdown signal to input thread", :thread => thread) | ||
|
||
# synchronize both ShutdownSignal and teardown below. by synchronizing both | ||
# we will avoid potentially sending a shutdown signal when the inputworker is | ||
# executing the teardown method. | ||
@run_mutex.synchronize do | ||
thread.raise(LogStash::ShutdownSignal) | ||
begin | ||
thread.wakeup # in case it's in blocked IO or sleeping | ||
rescue ThreadError | ||
end | ||
end | ||
end | ||
|
||
# sometimes an input is stuck in a blocking I/O so we need to tell it to teardown directly | ||
@inputs.each do |input| | ||
begin | ||
# input teardown must be synchronized since is can be called concurrently by | ||
# the input worker thread and from the pipeline thread shutdown method. | ||
# this means that input teardown methods must support multiple calls. | ||
@run_mutex.synchronize{input.teardown} | ||
@run_mutex.synchronize{input.stop} | ||
rescue LogStash::ShutdownSignal | ||
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. the 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 still necessary anywhere? I was trying to find out why it was there in the first place, but couldn't find a reason. 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. after re-analyzing the
I believe the I will open another issue 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. moved to #3886 |
||
# teardown could receive the ShutdownSignal, retry it | ||
retry | ||
end | ||
end | ||
|
||
# No need to send the ShutdownEvent to the filters/outputs nor to wait for | ||
# the inputs to finish, because in the #run method we wait for that anyway. | ||
end # def shutdown | ||
|
||
def plugin(plugin_type, name, *args) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ Gem::Specification.new do |gem| | |
gem.add_runtime_dependency "clamp", "~> 0.6.5" #(MIT license) for command line args/flags | ||
gem.add_runtime_dependency "filesize", "0.0.4" #(MIT license) for :bytes config validator | ||
gem.add_runtime_dependency "gems", "~> 0.8.3" #(MIT license) | ||
gem.add_runtime_dependency "concurrent-ruby", "~> 0.9.1" | ||
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. ty for fixing a specific version. +1 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. well actually I'm saying anything 0.9.* 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. Yeah, I meant 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. I expect 1.0 to break a lot of stuff. |
||
|
||
# TODO(sissel): Treetop 1.5.x doesn't seem to work well, but I haven't | ||
# investigated what the cause might be. -Jordan | ||
|
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.
suggestion: maybe log "stop called" instead of "stopping" it seems to better represent the reality?