Repository navigation
parser_multiline: match valid UTF-8 binary input with a UTF-8 regexp - #5717
Watson1978 merged 1 commit into
Conversation
Watson1978
left a comment
There was a problem hiding this comment.
Thanks for the fix. I checked it with in_tail and encoding not set. With the configuration in #5714, in_tail now reads past the café line. It emits a, c and the appended d and e, and the pos file moves to the end. The change also fixes the same stop when format_firstline is not set and format1 is a UTF-8 regexp, and when the last buffered event has the non-ASCII line and is flushed by multiline_flush_interval.
MUST: Please remove pylogs.db from the commit. It is a SQLite database with an empty logs table and is not related to this fix. fluentd.gemspec builds the file list from git ls-files, so the file would also be included in the released gem.
As the description notes, bytes that are not valid UTF-8 still raise the error. For example, with the configuration from #5714, if é is written as the single Latin-1 byte 0xE9, in_tail still stops reading that file. That is a separate problem in in_tail, and it is fine to leave it out of this PR.
in_tail passes lines to the parser as ASCII-8BIT strings when
`encoding` is not set. When format_firstline was a UTF-8 regexp, such
as one with \p{Alpha}, MultilineParser#firstline? raised
Encoding::CompatibilityError at the first non-ASCII line. The error
escaped from in_tail's parse_multilines, so in_tail read the same lines
again on every notification and never moved past them. When format1
was a UTF-8 regexp, MultilineRegexpParser#parse raised the same error
and in_tail dropped the whole multiline event.
Apply the retry added in fluent#5710 in MultilineRegexpParser#parse and
MultilineParser#firstline? too. The check and the UTF-8 copy move into
RegexpParser.utf8_text_for_retry, which runs only after the error, so
matching without the error costs the same as before. A binary string
with valid UTF-8 bytes is matched again as UTF-8.
Other incompatible input still raises Encoding::CompatibilityError.
Fixes fluent#5714
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Rajyavardhan <rajyavardhansing2003@gmail.com>
7ab0b08 to
cfe68f2
Compare
|
@Watson1978
|
Watson1978
left a comment
There was a problem hiding this comment.
Thanks for the update. All the points from my previous review are addressed in cfe68f2:
pylogs.dbis removed.RegexpParser#parse,MultilineRegexpParser#parseandMultilineParser#firstline?match directly first and callRegexpParser.utf8_text_for_retryonly afterEncoding::CompatibilityError.- The in_tail test uses
timeout: 10and checksassert_false(d.broken?).
I ran the configuration from #5714 with in_tail again. It emitted a and c, and then the appended d and e, all before shutdown. The pos file moved to the end of the file. test_parser_multiline.rb, test_parser_regexp.rb, in_tail/test_line_feeder.rb and test_in_tail.rb pass. LGTM.
Which issue(s) this PR fixes:
Fixes #5714
What this PR does / why we need it:
When
encodingis not set,in_tailpasses lines to the parser as binary (ASCII-8BIT) strings. If the multiline parser'sformat_firstlineorformat1is a UTF-8 regexp (for example, one with\p{Alpha}or a non-ASCII character), a line with non-ASCII bytes raisesEncoding::CompatibilityError:format_firstline:MultilineParser#firstline?raises. The error escapes fromin_tail'sparse_multilines, soin_tailreads the same lines again on every notification and never moves past them. In the reproduction from in_tail with the multiline parser stops reading a file at a non-ASCII line when format_firstline is a UTF-8 regexp #5714, no record is emitted from the file, the pos file stays at 0, and lines appended later are not read either.format1:MultilineRegexpParser#parseraises, andin_taildrops the whole multiline event with "invalid line found", including its ASCII lines.#5710 fixed the same error for the
regexpparser, butMultilineRegexpParser#parseandfirstline?do their own matching, so that fix did not reach them.Each method below matches directly first:
RegexpParser#parse(behavior unchanged)MultilineParser::MultilineRegexpParser#parseMultilineParser#firstline?If the match raises
Encoding::CompatibilityError, the method asksRegexpParser.utf8_text_for_retryfor a UTF-8 copy. The helper returns one only when the regexp is UTF-8 and the input is a binary string with valid UTF-8 bytes. The method then matches the copy. Otherwise it re-raises the error, so other incompatible input (invalid UTF-8 bytes, other encodings) still raisesEncoding::CompatibilityError.Tests:
test/plugin/test_parser_multiline.rb:firstline?andparsewith UTF-8 regexps on binary input, and the invalid-UTF-8 case that still raises.test/plugin/test_in_tail.rb: the reproduction from the issue (including a line appended after startup) for a UTF-8format_firstline, a UTF-8format1, and both. Each case checks the exact records emitted.With only
format_firstlinebeing UTF-8 (the configuration in the issue), the event starting withcafé:2still does not matchformat1 /^(?<key>\w+):.../and is dropped with a warning, because\wis ASCII-only.in_tailnow keeps reading the file and emits the other records.Docs Changes:
None.
Release Note:
parser_multiline: Fix
in_tailgetting stuck, or dropping multiline events, on valid UTF-8 input containing non-ASCII characters whenformat_firstlineorformatNis a UTF-8 regexp andencodingis not set.