From 60f9db56b04364573b93dd3bbd91d1f6ad30f8c8 Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Thu, 30 Jul 2026 10:16:02 -0600 Subject: [PATCH 1/2] engine: fail startup when HTTP server cannot start Signed-off-by: Eduardo Silva --- src/flb_engine.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/flb_engine.c b/src/flb_engine.c index d74cdd9deeb..b5408a2f0e1 100644 --- a/src/flb_engine.c +++ b/src/flb_engine.c @@ -1322,7 +1322,16 @@ int flb_engine_start(struct flb_config *config) if (config->http_server == FLB_TRUE) { config->http_ctx = flb_hs_create(config->http_listen, config->http_port, config); - flb_hs_start(config->http_ctx); + if (!config->http_ctx) { + flb_error("[engine] could not initialize HTTP server"); + return -1; + } + + ret = flb_hs_start(config->http_ctx); + if (ret != 0) { + flb_error("[engine] could not start HTTP server"); + return -1; + } } #endif From a3b358e236696f686ff3169b686cc12347bd2c28 Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Thu, 30 Jul 2026 10:16:07 -0600 Subject: [PATCH 2/2] tests: integration: cover HTTP server bind failure Signed-off-by: Eduardo Silva --- .../tests/test_internal_http_server_001.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/integration/scenarios/internal_http_server/tests/test_internal_http_server_001.py b/tests/integration/scenarios/internal_http_server/tests/test_internal_http_server_001.py index f1bf18a03f8..df20aeb24c6 100644 --- a/tests/integration/scenarios/internal_http_server/tests/test_internal_http_server_001.py +++ b/tests/integration/scenarios/internal_http_server/tests/test_internal_http_server_001.py @@ -1,8 +1,10 @@ import concurrent.futures import os +import socket import subprocess import pytest +from utils.fluent_bit_manager import FluentBitManager, FluentBitStartupError from utils.http_matrix import curl_supports_http2, run_curl_request from utils.test_service import FluentBitTestService @@ -146,3 +148,28 @@ def test_internal_http_server_http2_subset(): assert result["http_version"] == "2" finally: service.stop() + + +def test_internal_http_server_bind_failure_fails_startup(monkeypatch): + config_file = os.path.abspath( + os.path.join(os.path.dirname(__file__), "../config/internal_http_server.yaml") + ) + holder = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + holder.bind(("127.0.0.1", 0)) + port = holder.getsockname()[1] + fluent_bit = FluentBitManager(config_file) + + monkeypatch.setenv("FLUENT_BIT_HTTP_MONITORING_PORT", str(port)) + + def use_occupied_monitoring_port(_env_var_name, starting_port=0): + fluent_bit.http_monitoring_port = str(port) + + fluent_bit.set_http_monitoring_port = use_occupied_monitoring_port + + try: + with pytest.raises(FluentBitStartupError, match="exited early with code"): + fluent_bit.start() + assert fluent_bit.process.returncode != 0 + finally: + holder.close() + fluent_bit.stop()