Skip to content

Commit 831f2b9

Browse files
authored
Do not silently discard undelivered messages
The plugin no longer discards messages which it fails to send if the server disconnects and sends some content prior to the disconnection. Example situation before the fix: 1. A connection is established between a server and the plugin. 2. The plugin delivers some messages to the server. 2.1) It may or may not read something that it received from the server. 2.2) It sends the payload to the server. 3. The server sends some content back and disconnects. 4. The plugin tries to deliver some other messages to the server. 4.1) It tries to read (if r.any?) and expects to get an EOFError in case the server just died. 4.2) No error is thrown as some content just arrived from the server. It is discarded. 4.3) The first payload is written to the socket, no error being thrown. 4.4) The next payload finally fails with EOFError upon reading from the socket and an retry follows. This commit fixes the 4.1 and 4.2 phases. The reading is now performed repeatedly while there's still something to read left so that we don't miss the EOFError exception.
1 parent e1bea77 commit 831f2b9

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/logstash/outputs/tcp.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,14 @@ def register
150150
begin
151151
client_socket = connect unless client_socket
152152
r,w,e = IO.select([client_socket], [client_socket], [client_socket], nil)
153-
# don't expect any reads, but a readable socket might
154-
# mean the remote end closed, so read it and throw it away.
155-
# we'll get an EOFError if it happens.
156-
client_socket.sysread(16384) if r.any?
153+
loop do
154+
break if !r.any?
155+
# don't expect any reads, but a readable socket might
156+
# mean the remote end closed, so read it and throw it away.
157+
# we'll get an EOFError if it happens.
158+
client_socket.sysread(16384)
159+
r = IO.select([client_socket])
160+
end
157161

158162
# Now send the payload
159163
client_socket.syswrite(payload) if w.any?

0 commit comments

Comments
 (0)