Skip to content

in_tail with the multiline parser stops reading a file at a line with invalid UTF-8 bytes #5720

Backlog

Description

@Watson1978

Describe the bug

When the multiline parser raises an error on a line, in_tail stops reading the file. A line with bytes that are not valid UTF-8 (for example é written as the Latin-1 byte 0xE9) causes this in these cases:

The same error is logged about every second, and the position in the pos file does not move. No record is emitted from the file. This includes the lines before the bad line and the lines appended later.

LineFeeder#parse_multilines calls @parser.firstline?(line) (line_feeder.rb L187) and @parser.parse(lb) (L207) without a rescue. The error escapes, so in_tail reads the same lines again on the next notification and fails again. The single-line path rescues the error in convert_line_to_event (L164-L165). There, the regexp parser drops only the bad line with "invalid line found".

A related case: the last buffered event has the bad line and is flushed by multiline_flush_interval. flush_buffer (L84-L86) has no rescue either. The timer flush fails every second, and FileFeed#on_notify (L118-L125) keeps the buffer. TailWatcher runs the flush before it reads new lines (tail_watcher.rb L148-L149), so lines appended later are emitted only at shutdown.

To Reproduce

  1. Create the input file: printf 'a:1\ncaf\xe9:2\n continued\nc:3\n' > /path/to/input.log
  2. Run Fluentd with the configuration below.
  3. After a few seconds, append d:4 and e:5 to the file.

Results on master (31157cb) and v1.20.1:

Setting Result
encoding UTF-8, format_firstline /^\w+:/, format1 /^(?<key>\w+):(?<value>.*)/ (the configuration below) No record. "invalid byte sequence in UTF-8" is logged about every second. The pos file stays at 0. d:4 and e:5 are not read either.
No encoding, format_firstline /^\p{Alpha}+:/, format1 /^(?<key>\w+):(?<value>.*)/ Same, with "incompatible encoding regexp match (UTF-8 regexp with BINARY (ASCII-8BIT) string)".
encoding UTF-8, no format_firstline, format1 /^(?<key>\w+):(?<value>[^\n]*)/ Same as the first row.
No encoding, format_firstline /^\w+:/, format1 /^(?<key>\p{Alpha}+):(?<value>.*)/, input a:1\nb:2 caf\xe9\n a:1 is emitted. The timer flush logs "incompatible encoding regexp match" every second. d:4 and e:5 are emitted only at shutdown.
@type regexp, encoding UTF-8, expression /^(?<key>\w+):(?<value>.*)$/ (for comparison) a:1, c:3, d:4 and e:5. The bad line is dropped with "invalid line found".
The configuration below with cafe instead of caf\xe9 (for comparison) All records, including d:4 and e:5.

Expected behavior

in_tail keeps reading the file. Only the event with the bad line should be dropped with a warning, as the single-line parsers do. The other lines, and the lines appended later, should be emitted while Fluentd is running.

Your Environment

- Fluentd version: master (31157cba) 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
  encoding UTF-8
  <parse>
    @type multiline
    format_firstline /^\w+:/
    format1 /^(?<key>\w+):(?<value>.*)/
  </parse>
</source>

<match test>
  @type stdout
</match>

Your Error Log

[error]: invalid byte sequence in UTF-8
  [error]: <fluentd>/lib/fluent/plugin/parser_multiline.rb:107:in 'Regexp#match?'
  [error]: <fluentd>/lib/fluent/plugin/parser_multiline.rb:107:in 'Fluent::Plugin::MultilineParser#firstline?'
  [error]: <fluentd>/lib/fluent/plugin/in_tail/line_feeder.rb:187:in 'block in Fluent::Plugin::TailInput::LineFeeder#parse_multilines'
  [error]: <fluentd>/lib/fluent/plugin/in_tail/line_feeder.rb:186:in 'Array#each'
  [error]: <fluentd>/lib/fluent/plugin/in_tail/line_feeder.rb:186:in 'Fluent::Plugin::TailInput::LineFeeder#parse_multilines'
  ...

Additional context

If the file's encoding is known, from_encoding avoids the error. With from_encoding ISO-8859-1 and encoding UTF-8, the configuration above reads all lines.

Found while reviewing #5717, which fixes #5714 for valid UTF-8 bytes. With #5717, all the rows above give the same results.

#4007 reported the same firstline? error and was closed as stale. The options suggested there, suppress_repeated_stacktrace and ignore_repeated_log_interval, reduce the log, but in_tail still stops reading the file. A filter such as string-scrub does not help either, because the error happens in in_tail before any filter.

Activity

  1. added
    bug
    on Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions