fix: resolve mutex contention causing HTTP server unresponsiveness #8
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.
Problem
The HTTP server was unresponsive (timeouts >16s) when accessed during polling operations. This was caused by a mutex contention issue where
pollUpstreams()held the lock for the entire polling cycle, including slow HTTP requests (5+ seconds per upstream).Root Cause
When the HTTP server tried to call
getUpstreamsData(), it would block waiting for the same mutex, causing request timeouts.Solution
Minimize the critical section - only hold the mutex when reading/writing shared state, NOT during I/O:
This allows the HTTP server to respond to API requests in parallel with polling operations.
Results
Before
After
Test Results
Changes
File:
src/upstreams.zigpollUpstreams()to minimize mutex lock durationPollTargetstruct for snapshot dataPollResultstruct for async resultsTesting
Related
Completes the production hardening improvements:
This fix makes leanpoint production-ready with sub-second API response times and 100% uptime.