diff --git a/lib/fluent/plugin/buffer/file_chunk.rb b/lib/fluent/plugin/buffer/file_chunk.rb index 004260c7a2..38108d2219 100644 --- a/lib/fluent/plugin/buffer/file_chunk.rb +++ b/lib/fluent/plugin/buffer/file_chunk.rb @@ -244,9 +244,10 @@ def write_metadata(update: true) c: @created_at.to_i, m: (update ? Time.now : @modified_at).to_i, }) + bin = msgpack_packer.pack(data).to_s @meta.seek(0, IO::SEEK_SET) - @meta.truncate(0) - @meta.write(msgpack_packer.pack(data)) + @meta.write(bin) + @meta.truncate(bin.bytesize) end def file_rename(file, old_path, new_path, callback=nil) @@ -284,6 +285,7 @@ def create_new_chunk(path, perm) @meta.set_encoding(Encoding::ASCII_8BIT) @meta.sync = true @meta.binmode + write_metadata(update: false) rescue => e # This case is easier than enqueued!. Just removing pre-create buffer file @chunk.close rescue nil