From aa0a4725e36d2ccd99e92acb0687c154462bbe37 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Fri, 28 Aug 2026 18:08:14 +0900 Subject: [PATCH 1/3] engine: Plug a race on starting engine Signed-off-by: Hiroshi Hatake --- src/flb_engine.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/flb_engine.c b/src/flb_engine.c index b5408a2f0e1..3f1bccf7ed3 100644 --- a/src/flb_engine.c +++ b/src/flb_engine.c @@ -1038,6 +1038,16 @@ int flb_engine_failed(struct flb_config *config) ret = flb_pipe_w(config->ch_notif[1], &val, sizeof(uint64_t)); if (ret == -1) { flb_error("[engine] fail to dispatch FAILED message"); + + /* + * A library mode caller may be blocked on the notification + * channel waiting for this message: close the write end so the + * reader wakes up with EOF instead of waiting forever. + */ + if (config->ch_notif[1] != config->ch_notif[0]) { + mk_event_closesocket(config->ch_notif[1]); + config->ch_notif[1] = -1; + } } /* Waiting flushing log */ @@ -1379,17 +1389,24 @@ int flb_engine_start(struct flb_config *config) return -1; } - /* Signal that we have started */ - flb_engine_started(config); - + /* + * Segregate the backlog chunks before notifying the library mode + * caller: segregation closes chunks that cannot be routed, so it must + * not run concurrently with callers inspecting storage right after + * flb_start() returns. + */ ret = sb_segregate_chunks(config); if (ret < 0) { flb_error("[engine] could not segregate backlog chunks"); + flb_engine_failed(config); return -2; } + /* Signal that we have started */ + flb_engine_started(config); + config->grace_input = config->grace / 2; flb_info("[engine] Shutdown Grace Period=%d, Shutdown Input Grace Period=%d", config->grace, config->grace_input); From 4e10e23380bfbb62b14c78a43c58401ca950102a Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Fri, 28 Aug 2026 19:21:19 +0900 Subject: [PATCH 2/3] config: skip closing ch_notif[1] when it's no longer a valid fd Signed-off-by: Hiroshi Hatake --- src/flb_config.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/flb_config.c b/src/flb_config.c index eaff6c5f2ba..dc07e0eaa2c 100644 --- a/src/flb_config.c +++ b/src/flb_config.c @@ -623,7 +623,8 @@ void flb_config_exit(struct flb_config *config) /* Channel notifications */ if (config->ch_notif[0] > 0) { mk_event_closesocket(config->ch_notif[0]); - if (config->ch_notif[0] != config->ch_notif[1]) { + if (config->ch_notif[1] > 0 && + config->ch_notif[0] != config->ch_notif[1]) { mk_event_closesocket(config->ch_notif[1]); } } From 819ab7d55012a954343ba3822355307014513065 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Fri, 28 Aug 2026 19:38:34 +0900 Subject: [PATCH 3/3] engine: Ensure engine shutdown on library mode In library mode, flb_lib_worker() calls flb_engine_shutdown(config) only when flb_engine_start() returns -1 (in src/flb_lib.c, Lines 917-933). This branch sends FLB_ENGINE_FAILED, then returns -2, so it skips engine shutdown after partial initialization. Plugin and storage cleanup can be missed. Call flb_engine_shutdown(config) before returning, or update the caller to handle -2 without sending a second failure notification. Signed-off-by: Hiroshi Hatake --- src/flb_engine.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/flb_engine.c b/src/flb_engine.c index 3f1bccf7ed3..09ca590756e 100644 --- a/src/flb_engine.c +++ b/src/flb_engine.c @@ -1401,6 +1401,7 @@ int flb_engine_start(struct flb_config *config) { flb_error("[engine] could not segregate backlog chunks"); flb_engine_failed(config); + flb_engine_shutdown(config); return -2; }