Skip to content

Commit

Permalink
add workaround to prohibit to pass arguments to thread_create helper …
Browse files Browse the repository at this point in the history
…method
  • Loading branch information
tagomoris committed Apr 19, 2016
1 parent f458123 commit fe56d93
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/fluent/plugin/output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,9 @@ def start
@buffer_config.flush_threads.times do |i|
thread_title = "flush_thread_#{i}".to_sym
thread_state = FlushThreadState.new(nil, nil)
thread = thread_create(thread_title, thread_state, &method(:flush_thread_run))
thread = thread_create(thread_title) do
flush_thread_run(thread_state)
end
thread_state.thread = thread
@output_flush_threads_mutex.synchronize do
@output_flush_threads << thread_state
Expand Down
13 changes: 10 additions & 3 deletions lib/fluent/plugin_helper/thread.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,27 @@ def thread_wait_until_start
end
end

def thread_create(title, *args)
# Ruby 2.2.3 or earlier (and all 2.1.x) cause bug about Threading ("Stack consistency error")
# by passing splatted argument to `yield`
# https://bugs.ruby-lang.org/issues/11027
# We can enable to pass arguments after expire of Ruby 2.1 (& older 2.2.x)
# def thread_create(title, *args)
# Thread.new(*args) do |*t_args|
# yield *t_args
def thread_create(title)
raise ArgumentError, "BUG: title must be a symbol" unless title.is_a? Symbol
raise ArgumentError, "BUG: callback not specified" unless block_given?
m = Mutex.new
m.lock
thread = ::Thread.new(*args) do |*t_args|
thread = ::Thread.new do
m.lock # run thread after that thread is successfully set into @_threads
m.unlock
thread_exit = false
::Thread.current[:_fluentd_plugin_helper_thread_title] = title
::Thread.current[:_fluentd_plugin_helper_thread_started] = true
::Thread.current[:_fluentd_plugin_helper_thread_running] = true
begin
yield *t_args
yield
thread_exit = true
rescue => e
log.warn "thread exited by unexpected error", plugin: self.class, title: title, error_class: e.class, error: e
Expand Down

0 comments on commit fe56d93

Please sign in to comment.