Skip to content

Commit

Permalink
Merge pull request #1763 from fluent/fix-shutdown-call-sequence
Browse files Browse the repository at this point in the history
Combine before_shutdown and shutdown call in one sequence.
  • Loading branch information
repeatedly authored Nov 29, 2017
2 parents d635913 + c484d54 commit 5342dd2
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/fluent/root_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ def shutdown # Fluentd's shutdown sequence is stop, before_shutdown, shutdown, a

lifecycle_unsafe_sequence = ->(method, checker) {
operation = case method
when :before_shutdown then "preparing shutdown"
when :shutdown then "shutting down"
when :close then "closing"
else
Expand All @@ -228,11 +227,23 @@ def shutdown # Fluentd's shutdown sequence is stop, before_shutdown, shutdown, a
Thread.current.abort_on_exception = true
begin
if method == :shutdown
# To avoid Input#shutdown and Output#before_shutdown mismatch problem, combine before_shutdown and shutdown call in one sequence.
# The problem is in_tail flushes buffered multiline in shutdown but output's flush_at_shutdown is invoked in before_shutdown
operation = "preparing shutdown" # for logging
log.debug "#{operation} #{kind} plugin", type: Plugin.lookup_type_from_class(instance.class), plugin_id: instance.plugin_id
begin
instance.send(:before_shutdown) unless instance.send(:before_shutdown?)
rescue Exception => e
log.warn "unexpected error while #{operation} on #{kind} plugin", plugin: instance.class, plugin_id: instance.plugin_id, error: e
log.warn_backtrace
end
operation = "shutting down"
log.info "#{operation} #{kind} plugin", type: Plugin.lookup_type_from_class(instance.class), plugin_id: instance.plugin_id
instance.send(:shutdown) unless instance.send(:shutdown?)
else
log.debug "#{operation} #{kind} plugin", type: Plugin.lookup_type_from_class(instance.class), plugin_id: instance.plugin_id
instance.send(method) unless instance.send(checker)
end
instance.send(method) unless instance.send(checker)
rescue Exception => e
log.warn "unexpected error while #{operation} on #{kind} plugin", plugin: instance.class, plugin_id: instance.plugin_id, error: e
log.warn_backtrace
Expand All @@ -245,8 +256,6 @@ def shutdown # Fluentd's shutdown sequence is stop, before_shutdown, shutdown, a
lifecycle_safe_sequence.call(:stop, :stopped?)

# before_shutdown does force_flush for output plugins: it should block, so it's unsafe operation
lifecycle_unsafe_sequence.call(:before_shutdown, :before_shutdown?)

lifecycle_unsafe_sequence.call(:shutdown, :shutdown?)

lifecycle_safe_sequence.call(:after_shutdown, :after_shutdown?)
Expand Down

0 comments on commit 5342dd2

Please sign in to comment.