Skip to content

in_tcp: keep the connection and the other lines when the parser fails on a line - #5711

Merged
kenhys merged 4 commits into
fluent:masterfrom
Watson1978:in-tcp-rescue-parser-errors
Dec 2, 2026
Merged

kenhys merged 4 commits into
fluent:masterfrom
Watson1978:in-tcp-rescue-parser-errors

Conversation

@Watson1978

@Watson1978 Watson1978 commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

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

What this PR does / why we need it:
When the parser raised on a line, for example the json parser with time_format and a time that does not match, the error reached the server helper. It logged unexpected error on reading data and closed the connection. With batch emit, no line in that read was emitted. With single emit (<extract> with tag_key), the lines after the bad one were lost.

Now in_tcp rescues the parser error per line and logs failed to parse message at warn level. Only the bad line is dropped, and the connection stays open. Errors raised while emitting are not parser errors, so they still reach the server helper as before.

For a line that yields several records, such as a JSON array, the records yielded before the error are still emitted.

This also fixes the in_tcp side of #5691, where a UTF-8 regexp raises Encoding::CompatibilityError on a binary line.

This supersedes #5640. It is the same change rebased onto master, with the review comments applied. The commit keeps the original author as a co-author.

Docs Changes:
None.

Release Note:
in_tcp: when the parser fails on a line, keep the connection and the other lines, instead of closing the connection and losing them.

🤖 Generated with Claude Code

When the parser raised on a line, the error reached the server helper.
It closed the connection, and the other lines in the same read were lost.

Rescue the parser error per line, log it as a warning, and go on.
Errors raised while emitting are not parser errors, so they are re-raised.

This is based on fluent#5640 by Rafay Qayyum.

Co-authored-by: Rafay Qayyum <rafayqayyum786@gmail.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
@Watson1978 Watson1978 added this to the v1.21.0 milestone Dec 2, 2026
@Watson1978 Watson1978 added bug Something isn't working backport to v1.19 We will backport this fix to the LTS branch labels Dec 2, 2026
Watson1978 and others added 2 commits December 2, 2026 12:45
Mark the block as failed only when it raises. A parser that catches the
block's error and re-raises it later no longer turns an emit error into a
parse failure.

Skip building the warn arguments when warn is off. Make the tests wait for
the server thread instead of sleeping, and cover a parser error after the
parser has yielded a record.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
Timeout.timeout interrupts its block with Timeout::ExitException. A parser
that wraps parse in Timeout.timeout could turn a slow emit into a parse
failure. Also stop running the new test twice per data set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
Comment thread test/plugin/test_in_tcp.rb Resolved
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
@Watson1978
Watson1978 requested a review from kenhys December 2, 2026 07:51
@kenhys
kenhys merged commit 07e0ce8 into fluent:master Dec 2, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport to v1.19 We will backport this fix to the LTS branch bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

in_tcp: a parser error drops the other lines in the same read and closes the connection

2 participants