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.
@@ -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 */
