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

Synchronize access to @client_threads in LogStash::Outputs::Tcp #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lmars
Copy link

@lmars lmars commented Nov 21, 2014

From original PR elastic/logstash#1270


Logstash was consistently failing with the following error when a client connected to a TCP output:

NoMethodError: undefined method `write' for nil:NilClass
       register at /opt/logstash/lib/logstash/outputs/tcp.rb:92
           each at org/jruby/RubyArray.java:1613
       register at /opt/logstash/lib/logstash/outputs/tcp.rb:91
           call at org/jruby/RubyProc.java:271
         encode at /opt/logstash/lib/logstash/codecs/json.rb:45
        receive at /opt/logstash/lib/logstash/outputs/tcp.rb:143
         handle at /opt/logstash/lib/logstash/outputs/base.rb:86
     initialize at (eval):21
           call at org/jruby/RubyProc.java:271
         output at /opt/logstash/lib/logstash/pipeline.rb:266
   outputworker at /opt/logstash/lib/logstash/pipeline.rb:225
  start_outputs at /opt/logstash/lib/logstash/pipeline.rb:152

Logstash at the time was receiving a heavy stream of events, so this is likely the result of a race condition accessing @client_threads which is not thread safe, so this change synchronizes access to it across threads.

Signed-off-by: Lewis Marshall <lewis@lmars.net>
@elasticsearch-release
Copy link

Jenkins standing by to test this. If you aren't a maintainer, you can ignore this comment. Someone with commit access, please review this and clear it for Jenkins to run; then say 'jenkins, test it'.

@colinsurprenant
Copy link
Contributor

old issue followup: sorry about dropping this, it is still valid. I'll do a few online comments, if you are inclined on following up pease do, otherwise we can take what you proposed, make some modifications and merge that while preserving your commit for authorship.

end
@client_threads << client_thread
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of doing a "long" lock, I'd suggest keeping the client_thread var usage and simply do a short lock to update the @client_threads ivar like that

@client_threads_lock.synchronize do
  @client_threads << client_thread
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants