From 70a6a728a8fcb70dfdad586a12d768ca54f43262 Mon Sep 17 00:00:00 2001 From: ljxu18 Date: Fri, 23 Oct 2026 11:01:38 +0800 Subject: [PATCH 1/3] in_tail: flush pending multiline records before shutdown teardown Signed-off-by: ljxu18 --- plugins/in_tail/tail.c | 15 ++++++++++++++- plugins/in_tail/tail_config.h | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/plugins/in_tail/tail.c b/plugins/in_tail/tail.c index eb81a813d64..fcdad909e43 100644 --- a/plugins/in_tail/tail.c +++ b/plugins/in_tail/tail.c @@ -569,6 +569,19 @@ static void in_tail_pause(void *data, struct flb_config *config) /* Pause file system backend handlers */ flb_tail_fs_pause(ctx); + +#ifdef FLB_HAVE_PARSER + if (config->is_shutting_down == FLB_TRUE && ctx->ml_ctx != NULL && + ctx->multiline_shutdown_flushed == FLB_FALSE) { + /* + * Flush while processors, routes and outputs are still alive. Mark + * this first: appending the records can re-enter pause on a buffer + * limit, and the engine also pauses inputs again during teardown. + */ + ctx->multiline_shutdown_flushed = FLB_TRUE; + flb_ml_flush_pending_now(ctx->ml_ctx); + } +#endif } static void in_tail_resume(void *data, struct flb_config *config) @@ -890,5 +903,5 @@ struct flb_input_plugin in_tail_plugin = { .cb_resume = in_tail_resume, .cb_exit = in_tail_exit, .config_map = config_map, - .flags = 0 + .flags = FLB_INPUT_SHUTDOWN_FLUSH }; diff --git a/plugins/in_tail/tail_config.h b/plugins/in_tail/tail_config.h index 6790fe1d3b5..296341544e8 100644 --- a/plugins/in_tail/tail_config.h +++ b/plugins/in_tail/tail_config.h @@ -158,6 +158,7 @@ struct flb_tail_config { /* Multiline core engine */ struct flb_ml *ml_ctx; struct mk_list *multiline_parsers; + int multiline_shutdown_flushed; uint64_t files_static_count; /* number of items in the static file list */ struct mk_list files_static; From 9e19ca35c6acc2d657a0fe61a1ebb80148093f5d Mon Sep 17 00:00:00 2001 From: ljxu18 Date: Fri, 23 Oct 2026 11:01:41 +0800 Subject: [PATCH 2/3] tests: runtime: cover tail shutdown with pending CRI fragments Signed-off-by: ljxu18 --- .../data/common/parsers_cri_shutdown.conf | 24 ++++++ tests/runtime/in_tail.c | 77 ++++++++++++++++++- 2 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 tests/runtime/data/common/parsers_cri_shutdown.conf diff --git a/tests/runtime/data/common/parsers_cri_shutdown.conf b/tests/runtime/data/common/parsers_cri_shutdown.conf new file mode 100644 index 00000000000..37be743bd30 --- /dev/null +++ b/tests/runtime/data/common/parsers_cri_shutdown.conf @@ -0,0 +1,24 @@ +# Test-only parsers used by the in_tail shutdown regression test. +# +# The multiline engine flushes buffered groups on every timer tick and the +# built-in "cri" parser uses the default 4 second timeout. The shutdown test +# needs the pending fragment to stay buffered until the engine is stopped, so +# this parser mirrors the CRI semantics with a 60 second flush timeout. + +[PARSER] + Name cri_test + Format regex + Regex ^(?