Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/fluent/plugin/in_tcp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def start
es.add(time, record)
end
end
router.emit_stream(@tag, es)
router.emit_stream(@tag, es) unless es.empty?
buf.slice!(0, pos) if pos > 0
# If the buffer size exceeds the limit here, it means that the next message will definitely exceed the limit.
# So we should clear the buffer here. Otherwise, it will keep storing useless data until the next delimiter comes.
Expand Down
19 changes: 19 additions & 0 deletions test/plugin/test_in_tcp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,25 @@ def create_tcp_socket(host, port, &block)

assert_equal(["hello", "world"], d.events.collect { |event| event[2]["message"] })
end

test "do not emit an empty event stream for a read without a complete message" do |data|
d = create_driver(base_config + %!
<parse>
@type none
</parse>
#{data[:extract]}
!)
d.run(expect_records: 1, timeout: 10) do
create_tcp_socket('127.0.0.1', @port) do |sock|
sock.send("hel", 0)
sleep 1
sock.send("lo\n", 0)
end
end

assert_equal(["hello"], d.events.collect { |event| event[2]["message"] })
assert_equal(1, d.emit_count)
end
end

sub_test_case "message_length_limit" do
Expand Down