fluent/fluentd · error · FileChunkError

invalid modified_at

Error message

invalid modified_at

What it means

The last of restore_metadata's field checks: :m (modified_at) must satisfy data[:m].to_i > 0 or FileChunkError 'invalid modified_at' is raised. modified_at drives queue ordering (chunks are sorted by it on resume), so an invalid value would break flush ordering and is rejected instead.

Source

Thrown at lib/fluent/plugin/buffer/file_chunk.rb:225

        # used only for queued v0.12 buffer path or broken files
        def self.unique_id_from_path(path)
          if /\.(b|q)([0-9a-f]+)\.[^\/]*\Z/n =~ path # //n switch means explicit 'ASCII-8BIT' pattern
            return $2.scan(/../).map{|x| x.to_i(16) }.pack('C*')
          end
          nil
        end

        def restore_metadata(bindata)
          data = restore_metadata_with_new_format(bindata)

          unless data
            # old type of restore
            data = Fluent::MessagePackFactory.msgpack_unpacker(symbolize_keys: true).feed(bindata).read rescue {}
          end
          raise FileChunkError, "invalid meta data" if data.nil? || !data.is_a?(Hash)
          raise FileChunkError, "invalid unique_id" unless data[:id]
          raise FileChunkError, "invalid created_at" unless data[:c].to_i > 0
          raise FileChunkError, "invalid modified_at" unless data[:m].to_i > 0

          now = Fluent::Clock.real_now

          @unique_id = data[:id]
          @size = data[:s] || 0
          @created_at = data[:c]
          @modified_at = data[:m]

          @metadata.timekey = data[:timekey]
          @metadata.tag = data[:tag]
          @metadata.variables = data[:variables]
          @metadata.seq = data[:seq] || 0
        end

        def restore_metadata_partially(chunk)
          @unique_id = self.class.unique_id_from_path(chunk.path) || @unique_id
          @size = 0
          @created_at = chunk.ctime.to_i # birthtime isn't supported on Windows (and Travis?)

View on GitHub (pinned to dd45c6e18d)

Solutions

  1. Rely on fluentd's automatic handling: the broken chunk is logged, moved aside/deleted at resume, remaining chunks are listed in the log for audit
  2. Restore buffer dir from snapshot if the events must not be lost
  3. Prevent: graceful shutdown, disk monitoring, flush_at_shutdown awareness
  4. Inspect sibling chunks listed in the follow-up log line for related corruption
Defensive patterns

Strategy: try-catch

Validate before calling

Dir.glob('buffer/**/*.meta').each do |m|
  data = Fluent::MessagePackFactory.msgpack_unpacker(symbolize_keys: true)
                .feed(File.binread(m)).read rescue {}
  warn "#{m}: invalid modified_at" unless data.is_a?(Hash) && data[:m].to_i > 0
end

Try / catch

begin
  Fluent::Plugin::Buffer::FileChunk.new(metadata, path, :staged)
rescue Fluent::Plugin::Buffer::FileChunkError => e
  log.error "dropping unrestoreable chunk #{path}: #{e.message}"
  File.rename(path, "#{path}.broken") rescue nil
end

Prevention

When it happens

Trigger: Same as the sibling checks — an empty/garbage fallback Hash ({}) or a meta file whose :m is missing, zero, or non-numeric; typically after a crash mid-write of the .meta file.

Common situations: Power failure or SIGKILL during buffered output; truncated .meta after disk-full; buffer directory copied/restored inconsistently.

Related errors


AI-assisted analysis of fluent/fluentd@dd45c6e18d (2026-08-21). Data as JSON: /api/errors/37851a59298a53ce. Report an issue: GitHub.