-
Notifications
You must be signed in to change notification settings - Fork 1.9k
http_server: run internal HTTP server on dedicated worker thread #11770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jackfletch
wants to merge
2
commits into
fluent:master
Choose a base branch
from
jackfletch:fix-http-server-deadlock
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...integration/scenarios/internal_http_server/config/internal_http_server_exec_deadlock.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| service: | ||
| flush: 1 | ||
| grace: 1 | ||
| log_level: info | ||
| http_server: on | ||
| http_listen: 127.0.0.1 | ||
| http_port: ${FLUENT_BIT_HTTP_MONITORING_PORT} | ||
|
|
||
| pipeline: | ||
| inputs: | ||
| - name: exec | ||
| tag: test | ||
| command: curl -s http://127.0.0.1:${FLUENT_BIT_HTTP_MONITORING_PORT}/api/v1/metrics/prometheus | ||
| interval_sec: 1 | ||
| buf_size: 128k | ||
|
|
||
| outputs: | ||
| - name: "null" | ||
| match: "*" |
63 changes: 63 additions & 0 deletions
63
...ation/scenarios/internal_http_server/tests/test_internal_http_server_exec_deadlock_001.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import os | ||
| import time | ||
|
|
||
| from utils.http_matrix import run_curl_request | ||
| from utils.test_service import FluentBitTestService | ||
|
|
||
|
|
||
| class Service: | ||
| def __init__(self): | ||
| self.config_file = os.path.abspath( | ||
| os.path.join(os.path.dirname(__file__), "../config/internal_http_server_exec_deadlock.yaml") | ||
| ) | ||
| self.service = FluentBitTestService(self.config_file) | ||
|
|
||
| def start(self): | ||
| self.service.start() | ||
| self.flb = self.service.flb | ||
| self.base_url = f"http://127.0.0.1:{self.flb.http_monitoring_port}" | ||
|
|
||
| def stop(self): | ||
| self.service.stop() | ||
|
|
||
| def request(self, path, *, method="GET", http_mode="http1.1"): | ||
| return run_curl_request( | ||
| f"{self.base_url}{path}", | ||
| method=method, | ||
| http_mode=http_mode, | ||
| ) | ||
|
|
||
|
|
||
| def test_http_server_responsive_after_exec_self_request(): | ||
| """The built-in HTTP server must remain responsive after the exec input | ||
| plugin makes an HTTP request to it. Before the fix, the exec child | ||
| process (curl) and the HTTP server shared the same event loop, causing | ||
| a deadlock that made the server permanently unresponsive.""" | ||
|
|
||
| service = Service() | ||
| service.start() | ||
|
|
||
| try: | ||
| # Verify the server works before exec fires | ||
| result = service.request("/api/v1/uptime") | ||
| assert result["status_code"] == 200 | ||
| assert "uptime_sec" in result["body"] | ||
|
|
||
| # Wait for exec to fire (interval_sec=1) plus a small buffer | ||
| time.sleep(2) | ||
|
|
||
| # Verify the server is still responsive after exec has fired | ||
| result = service.service.wait_for_condition( | ||
| lambda: ( | ||
| response | ||
| if response["status_code"] == 200 and "uptime_sec" in response["body"] | ||
| else None | ||
| ) if (response := service.request("/api/v1/uptime")) else None, | ||
| timeout=10, | ||
| interval=1, | ||
| description="HTTP server responsive after exec self-request", | ||
| ) | ||
| assert result["status_code"] == 200 | ||
| assert "uptime_sec" in result["body"] | ||
| finally: | ||
| service.stop() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: fluent/fluent-bit
Length of output: 2147
🏁 Script executed:
Repository: fluent/fluent-bit
Length of output: 6066
🏁 Script executed:
Repository: fluent/fluent-bit
Length of output: 3721
🏁 Script executed:
Repository: fluent/fluent-bit
Length of output: 2208
🏁 Script executed:
Repository: fluent/fluent-bit
Length of output: 1686
🏁 Script executed:
Repository: fluent/fluent-bit
Length of output: 4701
🏁 Script executed:
Repository: fluent/fluent-bit
Length of output: 4286
🏁 Script executed:
Repository: fluent/fluent-bit
Length of output: 2593
🏁 Script executed:
Repository: fluent/fluent-bit
Length of output: 3860
🏁 Script executed:
Repository: fluent/fluent-bit
Length of output: 2507
Data race on shared hs buffers after moving HTTP server to worker thread
After this change the HTTP server runs on worker threads instead of integrating into the main event loop. The endpoint request handlers (e.g.,
cb_metrics,cb_storagein the API endpoints) now run concurrently with the engine's metric-push functions (flb_hs_push_metrics,flb_hs_push_pipeline_metrics,flb_hs_push_storage_metrics,flb_hs_push_health_metrics), with no synchronization:buf->users++and readbuf->data/buf->raw_datapointers (worker thread)flb_hs_buf_cleanup()which checks/writesusers,pending_free, and nullsdata/raw_data(main engine thread)usersfield instruct flb_hs_bufis plainint— not atomic — so concurrent increment/decrement can silently miscount, leading to use-after-free or leaksAdd synchronization (e.g.,
pthread_mutex_t) guarding access toflb_hs_bufstructures andhs->health_metricslist mutations before merge.🤖 Prompt for AI Agents