Skip to content

Commit 750e393

Browse files
michaelweisersuyograo
authored andcommitted
Fix race condition in tcp output server mode
A race condition in tcp output could cause the shipper to die with an exception because the thread's [:client] property would not yet be initialised when the main program would start to put data into it: NoMethodError: undefined method `write' for nil:NilClass register at lib/logstash/outputs/tcp.rb:143 each at org/jruby/RubyArray.java:1613 register at lib/logstash/outputs/tcp.rb:142 call at org/jruby/RubyProc.java:271 encode at lib/logstash/codecs/json_lines.rb:50 receive at lib/logstash/outputs/tcp.rb:208 handle at lib/logstash/outputs/base.rb:86 initialize at (eval):47 call at org/jruby/RubyProc.java:271 output at lib/logstash/pipeline.rb:266 outputworker at lib/logstash/pipeline.rb:225 start_outputs at lib/logstash/pipeline.rb:152
1 parent 3f955ad commit 750e393

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/logstash/outputs/tcp.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ def register
7070

7171
@accept_thread = Thread.new(@server_socket) do |server_socket|
7272
loop do
73-
client_thread = Thread.start(server_socket.accept) do |client_socket|
73+
Thread.start(server_socket.accept) do |client_socket|
7474
client = Client.new(client_socket, @logger)
7575
Thread.current[:client] = client
76+
@client_threads << Thread.current
7677
client.run
7778
end
78-
@client_threads << client_thread
7979
end
8080
end
8181

0 commit comments

Comments
 (0)