Skip to content

in_tcp: keep the message_length_limit discard state per connection - #5648

Closed
Raed2180416 wants to merge 1 commit into
fluent:masterfrom
Raed2180416:in-tcp-discard-per-connection
Closed

Raed2180416 wants to merge 1 commit into
fluent:masterfrom
Raed2180416:in-tcp-discard-per-connection

Conversation

@Raed2180416

Copy link
Copy Markdown

Which issue(s) this PR fixes:
Fixes #5647

What this PR does / why we need it:

in_tcp kept discard_till_next_delimiter in a local variable of start, so every connection shared it. When one connection sent more than message_length_limit bytes without a delimiter, its buffer was cleared and the flag was set. The next delimiter to arrive then reset the flag and was dropped, even when it came from another connection, and the rest of the long message was emitted as a record, because the flag was already reset by the time its own delimiter came.

This moves the flag into the connection block, as in_syslog does for the same flag, so a connection discards only its own data until its own next delimiter. The read loop is otherwise unchanged. server_create is replaced with server_create_connection so the block runs once per connection and discard_till_next_delimiter is a per-connection local. The client check stays inside the data callback, so when a disallowed client is closed does not change.

With two connections, message_length_limit 10, and @type none:

A: "x" * 11   (no delimiter)
B: "hello\n"
A: "tail\n"
B: "world\n"

Before: ["tail", "world"] — B's line is lost and the tail of A's long message is emitted. After: ["hello", "world"].

Verified: bundle exec ruby -Ilib -Itest test/plugin/test_in_tcp.rb — the new test discard only the data of the connection that exceeded the limit fails on master with <["hello", "world"]> expected but was <["tail", "world"]> for both the batch-emit and single-emit paths, and the file passes 32 tests, 75 assertions, 0 failures after the change. rubocop lib/fluent/plugin/in_tcp.rb test/plugin/test_in_tcp.rb reports no offenses.

Docs Changes:
N/A

Release Note:
in_tcp: keep the message_length_limit discard state per connection

discard_till_next_delimiter was a local variable of start, so every
connection shared it. When one connection exceeded message_length_limit
and had its buffer cleared, the flag stayed set, and the next delimiter
from any connection, whichever came first, was dropped as if it were the
tail of the long message. The rest of the long message was then emitted
as a record, because the flag was already reset when its own delimiter
came.

Move the flag into the connection block, as in_syslog already does, so
each connection discards only its own data until its own next delimiter.
The read loop is unchanged apart from that scope.

Fixes fluent#5647

Signed-off-by: Raed <Raed2180416@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 17, 2026 21:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@Watson1978

Copy link
Copy Markdown
Contributor

Thank you for the fix and the clear test.

#5624 already includes the same change in its commit 185ee75. With it, in_tcp keeps the discard flag for each connection, as in_syslog does. I checked that both examples in #5647 are fixed on the current head of #5624.

The two PRs change the same block of in_tcp, so I'm closing this one in favor of #5624.

@Watson1978 Watson1978 closed this Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

in_tcp: message_length_limit makes another connection lose a line and emits the rest of the long message

3 participants