{"record":{"id":"e1313630c1a22b13","repo":"fluent/fluentd","slug":"staged-file-chunk-is-empty-e13136","errorCode":null,"errorMessage":"staged file chunk is empty","messagePattern":"staged file chunk is empty","errorType":"exception","errorClass":"FileChunkError","httpStatus":null,"severity":"critical","filePath":"lib/fluent/plugin/buffer/file_single_chunk.rb","lineNumber":275,"sourceCode":"            @chunk.set_encoding(Encoding::ASCII_8BIT)\n            @chunk.sync = true\n            @chunk.binmode\n          rescue => e\n            # Here assumes \"Too many open files\" like recoverable error so raising BufferOverflowError.\n            # If other cases are possible, we will change error handling with proper classes.\n            raise BufferOverflowError, \"can't create buffer file for #{path}. Stop creating buffer files: error = #{e}\"\n          end\n\n          @state = :unstaged\n          @bytesize = 0\n          @commit_position = @chunk.pos # must be 0\n          @adding_bytes = 0\n          @adding_size = 0\n        end\n\n        def load_existing_staged_chunk(path)\n          @path = path\n          raise FileChunkError, \"staged file chunk is empty\" if File.size(@path).zero?\n\n          @chunk = File.open(@path, 'rb+')\n          @chunk.set_encoding(Encoding::ASCII_8BIT)\n          @chunk.sync = true\n          @chunk.binmode\n          @chunk.seek(0, IO::SEEK_END)\n\n          restore_metadata\n\n          @state = :staged\n          @bytesize = @chunk.size\n          @commit_position = @chunk.pos\n          @adding_bytes = 0\n          @adding_size = 0\n        end\n\n        def load_existing_enqueued_chunk(path)\n          @path = path","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/fluent/fluentd/blob/dd45c6e18dc7be33b5e5a0f0767bf46307ff5626/lib/fluent/plugin/buffer/file_single_chunk.rb#L257-L293","documentation":"For the single-file buffer plugin (buf_file_single), FileSingleChunk#load_existing_staged_chunk re-opens staged chunk files (prefix.<key>.b<hex>.<suffix>) at startup. A staged chunk must already contain appended data; if File.size(path) is zero it raises FileChunkError 'staged file chunk is empty', which prevents fluentd from starting.","triggerScenarios":"A staged chunk file of 0 bytes in the buffer directory: fluentd crashed between creating the stage file and the first write/flush, a disk-full short write occurred, or the file was truncated/copied incompletely.","commonSituations":"kill -9/OOM during high-throughput ingestion; buffer partition full or read-only; partial rsync of the buffer dir; test artifacts left in the buffer path.","solutions":["Stop fluentd and delete or quarantine the zero-byte staged file named in the error (and any related .meta), then restart.","Check why it was created empty: disk space, OOM kills in dmesg, crash timing during first append.","Keep the buffer on a healthy, monitored partition and use graceful restarts (SIGTERM with flush) to avoid partial writes."],"exampleFix":"# before: startup fails on 'staged file chunk is empty'\n# after: remove the empty staged chunk and restart\nsudo systemctl stop fluentd\nfind /var/log/fluent/buffer -name '*.b*.buf' -size 0 -print -delete\nsudo systemctl start fluentd","handlingStrategy":"validation","validationCode":"# preflight: zero-size staged chunk files (single-mode buffer)\nDir.glob('/var/log/fluent/buffer/*.b*.buf').each do |f|\n  warn \"empty staged chunk: #{f}\" if File.size(f).zero?\nend","typeGuard":null,"tryCatchPattern":"begin\n  chunk = Fluent::Plugin::Buffer::FileSingleChunk.new(metadata, path, :staged, key)\nrescue Fluent::Plugin::Buffer::FileChunkError => e\n  log.error \"removing empty staged chunk #{path}: #{e.message}\"\n  File.delete(path) if File.size(path).zero?\nend","preventionTips":["Avoid kill -9; use SIGTERM so in-flight appends complete.","Monitor buffer disk space and OOM events.","Do not truncate or copy buffer files while fluentd runs.","Add a zero-size file scan to your restart runbook."],"tags":["fluentd","ruby","file-buffer","empty-file","startup-failure"],"backgroundTag":"empty-buffer-chunk-file","analyzedSha":"dd45c6e18dc7be33b5e5a0f0767bf46307ff5626","analyzedAt":"2026-08-21T16:22:07.332Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}