Skip to content

Commit 71208f6

Browse files
committed
in_tail: fix data loss on shutdown with buffered data
Unprocessed data in the internal buffer is currently discarded when Fluent Bit stops, causing data loss because the DB offset is already advanced. This patch fixes the issue by rewinding the file offset by the remaining buffer length on exit, ensuring the data is re-read on the next startup. Signed-off-by: jinyong.choi <[email protected]>
1 parent 7ded9ae commit 71208f6

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

plugins/in_tail/tail_file.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,6 +1448,29 @@ void flb_tail_file_remove(struct flb_tail_file *file)
14481448
flb_plg_debug(ctx->ins, "inode=%"PRIu64" removing file name %s",
14491449
file->inode, file->name);
14501450

1451+
if (file->buf_len > 0) {
1452+
/*
1453+
* If there is data in the buffer, it means it was not processed.
1454+
* We must rewind the offset to ensure this data is re-read on restart.
1455+
*/
1456+
off_t old_offset = file->offset;
1457+
1458+
if (file->offset > file->buf_len) {
1459+
file->offset -= file->buf_len;
1460+
} else {
1461+
file->offset = 0;
1462+
}
1463+
1464+
flb_plg_debug(ctx->ins, "inode=%"PRIu64" rewind offset for %s: old=%"PRId64" new=%"PRId64" (buf_len=%lu)",
1465+
file->inode, file->name, old_offset, file->offset, (unsigned long)file->buf_len);
1466+
1467+
#ifdef FLB_HAVE_SQLDB
1468+
if (ctx->db) {
1469+
flb_tail_db_file_offset(file, ctx);
1470+
}
1471+
#endif
1472+
}
1473+
14511474
if (file->decompression_context != NULL) {
14521475
flb_decompression_context_destroy(file->decompression_context);
14531476
}

0 commit comments

Comments
 (0)