in_tail with the multiline parser stops reading a file at a non-ASCII line when format_firstline is a UTF-8 regexp
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 停滞
- 技術スタック
- ruby
調査の方向性
Read lib/fluent/plugin/parser_multiline.rb at MultilineRegexpParser#parse and MultilineParser#firstline?, then compare the matching retry added for the regexp parser in #5710. Check the related in_tail line feeder behavior in lib/fluent/plugin/in_tail/line_feeder.rb and its tests. Done means UTF-8 multiline patterns handle binary input without stopping file reads or dropping unrelated records; pull request #5717 is already open.
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
When format_firstline of the multiline parser is a UTF-8 regexp, in_tail stops reading a file at the first line with non-ASCII bytes. A regexp is UTF-8 when it has a non-ASCII character or a property such as \p{Alpha}. The same error is logged about every second, and the position in the pos file does not move. No record is emitted from that file. This includes the ASCII lines before the non-ASCII line and the lines appended later.
When encoding is not set, in_tail passes lines to the parser as binary (ASCII-8BIT) strings. MultilineParser#firstline? matches them with the UTF-8 regexp (parser_multiline.rb L107), and Regexp#match? raises Encoding::CompatibilityError. The exception escapes from parse_multilines (line_feeder.rb L186-L187), so in_tail reads the same lines again on the next notification and fails again.
When format1 is a UTF-8 regexp, MultilineRegexpParser#parse (parser_multiline.rb L34) raises the same error. In this case in_tail logs "invalid line found" and drops the whole multiline event, including its ASCII lines.
#5710 fixed this error for the regexp parser (#5691). MultilineRegexpParser#parse and firstline? do their own matching, so the fix does not apply to them.
To Reproduce
- Create the input file:
printf 'a:1\ncaf\xc3\xa9:2\n continued\nc:3\n' > /path/to/input.log - Run Fluentd with the configuration below.
- After a few seconds, append
d:4ande:5to the file.
Results on master (683dd17a) and v1.20.1:
| Parser setting | Result |
|---|---|
format_firstline /^\p{Alpha}+:/, format1 /^(?<key>\w+):(?<value>.*)/ (the configuration below) |
No record. The error below is logged about every second. The pos file stays at 0. d:4 and e:5 are not read either. |
format_firstline /^\w+:/, format1 /^(?<key>\p{Alpha}+):(?<value>.*)/ |
Only c:3 is emitted. a:1 and the next two lines form one event, which is dropped with "invalid line found". |
format_firstline /^\w+:/, format1 /^(?<key>\w+):(?<value>.*)/ (for comparison) |
Two records: a:1 with the next two lines, and c:3. |
With encoding UTF-8 in in_tail, neither UTF-8 setting raises the error.
Expected behavior
in_tail keeps reading the file. Ideally, a line with valid UTF-8 bytes is matched with the UTF-8 regexp, as the regexp parser does since #5710. At least, only the event with the line should be dropped with a warning, and in_tail should go on reading the file.
Your Environment
- Fluentd version: master (683dd17a) and v1.20.1
- Package version: -
- Operating system: Ubuntu 24.04.5 LTS
- Kernel version: 6.8.0-151-generic
- Ruby: 4.0.10
Your Configuration
<source>
@type tail
tag test
path /path/to/input.log
pos_file /path/to/input.pos
read_from_head true
multiline_flush_interval 1s
<parse>
@type multiline
format_firstline /^\p{Alpha}+:/
format1 /^(?<key>\w+):(?<value>.*)/
</parse>
</source>
<match test>
@type stdout
</match>
Your Error Log
With format_firstline /^\p{Alpha}+:/, this is logged about every second:
[info]: #0 following tail of /path/to/input.log
[error]: #0 incompatible encoding regexp match (UTF-8 regexp with BINARY (ASCII-8BIT) string)
[error]: #0 <fluentd>/lib/fluent/plugin/parser_multiline.rb:107:in 'Regexp#match?'
[error]: #0 <fluentd>/lib/fluent/plugin/parser_multiline.rb:107:in 'Fluent::Plugin::MultilineParser#firstline?'
[error]: #0 <fluentd>/lib/fluent/plugin/in_tail/line_feeder.rb:187:in 'block in Fluent::Plugin::TailInput::LineFeeder#parse_multilines'
[error]: #0 <fluentd>/lib/fluent/plugin/in_tail/line_feeder.rb:186:in 'Array#each'
[error]: #0 <fluentd>/lib/fluent/plugin/in_tail/line_feeder.rb:186:in 'Fluent::Plugin::TailInput::LineFeeder#parse_multilines'
...
With format1 /^(?<key>\p{Alpha}+):(?<value>.*)/:
[warn]: #0 invalid line found file="/path/to/input.log" line="a:1\ncaf\xC3\xA9:2\n continued" error="incompatible encoding regexp match (UTF-8 regexp with BINARY (ASCII-8BIT) string)"
Additional context
encoding UTF-8 in in_tail works around this. A possible fix is to apply the retry of #5710 in MultilineRegexpParser#parse and firstline? too.
- 主要言語
- Ruby
- スター
- 13.6k
- フォーク
- 1.4k
- 平均マージ
- 1日 10時間
- マージ済み PR(30日)
- 79
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
fluent/fluentd のほかの issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
メンテナーはふだん 1 日以内に返信
-
A <secondary> output cannot roll back a chunk: rollback_write always raises ArgumentError対応中かも @lbarrosby が 18 日前に担当しました。 オープンbug
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
parser_syslog: message_format auto parses RFC 3164 messages with an RFC 3339 timestamp as RFC 5424対応中かも @rafayqayyum が 17 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
fluent/fluentd#5631 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
parser_syslog: the regexp engine for RFC 5424 can match the header later in the message and corrupt the record対応中かも @rafayqayyum が 17 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
fluent/fluentd#5630 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
🐛 bug 👩💻 équipe CE
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
betagouv/conseillers-entreprises#4835 ·
メンテナーはふだん 1 日以内に返信
-
Action: a `test` glob with a gem older than 1.9.0 fails with `no such file` and no version hintオープンbacklog enhancement github_actions priority: low risk: low
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
davidteren/mutineer#646 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
metanorma/isodoc#965 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
verified
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
zammad/zammad#6636 · コメント 1 件 ·
メンテナーはふだん 4 日以内に返信