Skip to content

Fix handling of HTTP server request overloads#2236

Draft
Neverlord wants to merge 1 commit intomainfrom
topic/neverlord/http-overload
Draft

Fix handling of HTTP server request overloads#2236
Neverlord wants to merge 1 commit intomainfrom
topic/neverlord/http-overload

Conversation

@Neverlord
Copy link
Member

  • http_request_producer_impl::push has a bug: the SPSC buffer returning 0 does not mean the item has been rejected but merely that the capacity reached zero
  • if the server received too many requests, it killed all in-flight requests that were still pending in the buffer

This set of changes introduces try_push on SPSC buffers that rejects additional items when at or above capacity. Further, the HTTP server now sends an error only in response to the rejected request. Pending requests are unaffected.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a critical bug in the HTTP server's request handling where the SPSC buffer's return value was misinterpreted, causing all in-flight requests to be killed when the server received too many requests. The fix introduces a new try_push method that properly enforces capacity limits and updates the error handling to only reject the overflowing request while keeping pending requests intact.

Changes:

  • Added try_push method to spsc_buffer that treats capacity as a hard limit, unlike push which allows exceeding capacity for burst absorption
  • Updated http_request_producer_impl to use try_push instead of push for proper rejection semantics
  • Changed error handling from shutting down all in-flight requests to sending a 503 Service Unavailable response only for rejected requests

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
libcaf_core/caf/async/spsc_buffer.hpp Adds try_push method with hard capacity enforcement and updates documentation to clarify soft vs hard limit behavior
libcaf_net/caf/net/http/with.cpp Switches to try_push and replaces router shutdown with proper 503 error response for rejected requests

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +110 to +120
bool try_push(const T& item) {
lock_type guard{mtx_};
CAF_ASSERT(producer_ != nullptr);
CAF_ASSERT(!flags_.closed);
if (buf_.size() >= capacity_)
return false;
buf_.push_back(item);
if (buf_.size() == 1 && consumer_)
consumer_->on_producer_wakeup();
return true;
}
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new try_push method lacks test coverage. Consider adding unit tests to verify its behavior, especially for edge cases like:

  • Attempting to push when the buffer is exactly at capacity
  • Attempting to push when the buffer is above capacity (if that's possible through the regular push method)
  • Verifying that try_push returns true when there is available capacity
  • Verifying that the consumer is properly awakened when the buffer transitions from empty to non-empty

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Jan 21, 2026

Codecov Report

❌ Patch coverage is 42.85714% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.20%. Comparing base (eba4798) to head (3f18b9a).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
libcaf_core/caf/async/spsc_buffer.hpp 60.00% 2 Missing and 2 partials ⚠️
libcaf_net/caf/net/http/with.cpp 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2236      +/-   ##
==========================================
- Coverage   71.27%   71.20%   -0.07%     
==========================================
  Files         635      633       -2     
  Lines       30676    30691      +15     
  Branches     3327     3328       +1     
==========================================
- Hits        21865    21855      -10     
- Misses       6935     6958      +23     
- Partials     1876     1878       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@riemass riemass closed this Jan 21, 2026
@riemass riemass reopened this Jan 21, 2026
@riemass
Copy link
Member

riemass commented Jan 21, 2026

Sorry for the noise. Closed by mistake while looking at the PR from phone.

@Neverlord Neverlord force-pushed the topic/neverlord/http-overload branch from 66a1163 to 3f18b9a Compare January 22, 2026 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants