From 075ee4d1caa03c8bafb7f13082b3136ef3d10f49 Mon Sep 17 00:00:00 2001 From: Takahiro Yamashita Date: Sun, 17 Oct 2021 11:16:21 +0900 Subject: [PATCH] in_tail: create stream_id by file inode(#4190) If stream_id is created by filename, rotated file id will be same. It causes releasing new multiline instance after file rotation. Signed-off-by: Takahiro Yamashita --- plugins/in_tail/tail_file.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/plugins/in_tail/tail_file.c b/plugins/in_tail/tail_file.c index 958bd58d9a5..134282d7180 100644 --- a/plugins/in_tail/tail_file.c +++ b/plugins/in_tail/tail_file.c @@ -795,6 +795,7 @@ int flb_tail_file_append(char *path, struct stat *st, int mode, size_t tag_len; struct flb_tail_file *file; struct stat lst; + flb_sds_t inode_str; if (!S_ISREG(st->st_mode)) { return -1; @@ -882,18 +883,30 @@ int flb_tail_file_append(char *path, struct stat *st, int mode, /* Multiline core mode */ if (ctx->ml_ctx) { + /* + * Create inode str to get stream_id. + * + * If stream_id is created by filename, + * it will be same after file rotation and it causes invalid destruction. + * https://github.com/fluent/fluent-bit/issues/4190 + * + */ + inode_str = flb_sds_create_size(64); + flb_sds_printf(&inode_str, "%"PRIu64, file->inode); /* Create a stream for this file */ ret = flb_ml_stream_create(ctx->ml_ctx, - file->name, file->name_len, + inode_str, flb_sds_len(inode_str), ml_flush_callback, file, &stream_id); if (ret != 0) { flb_plg_error(ctx->ins, "could not create multiline stream for file: %s", - file->name); + inode_str); + flb_sds_destroy(inode_str); goto error; } file->ml_stream_id = stream_id; + flb_sds_destroy(inode_str); } /* Local buffer */