Handle source connections concurrently - #177
Open
ameba23 wants to merge 5 commits into
Open
Conversation
ameba23
marked this pull request as draft
September 11, 2026 15:15
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved critical request-capacity and cancellation issues, plus a moderate pipelining timeout issue, block approval.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Improves proxy-client forwarding with concurrent HTTP/2 handling, HTTP/1.1 reconnects, deadlines, cancellation, and configurable limits.
Changes:
- Adds configurable in-flight request limits and timeouts.
- Implements request-body cancellation and response idle tracking.
- Adds concurrency, reconnect, timeout tests, CLI options, and documentation.
File summaries
| File | Summary |
|---|---|
src/main.rs |
Adds client configuration flags. |
src/lib.rs |
Integrates concurrency and reconnect logic. Critical: queued or timed-out requests can retain permits; oversized semaphore limits can panic. |
src/http_version.rs |
Supports the new request body abstraction. |
src/client_request/upload.rs |
Provides cancellable upload handling. Critical: canceled uploads can retain semaphore permits. |
src/client_request/tests.rs |
Tests concurrency, cancellation, timeouts, and streaming. |
src/client_request/response_idle.rs |
Tracks response write activity. Moderate: shared response state can mishandle pipelined responses. |
src/client_request/mod.rs |
Implements forwarding, deadlines, and capacity tracking. Critical: dropped bodies or canceled uploads can retain request slots. |
README.md |
Documents the new configuration options. |
Review details
- Files reviewed: 8/8 changed files
- Comments generated: 6
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+216
to
+220
| _ = tokio::time::sleep_until(deadline), if !uploaded => { | ||
| // Headers may already have reached the caller, so a 504 can no | ||
| // longer replace them. Cancel the upload instead. | ||
| drop(upload_guard); | ||
| return ForwardResult { reconnect: http1 || sender.is_closed(), sender }; |
Collaborator
Author
There was a problem hiding this comment.
I have a fix for this in a separate branch, but it ended up being quite a bit of extra code for something debatably quite edge-casey. Im not sure if i want to merge it here.
Comment on lines
+239
to
+246
| impl TrackedBody { | ||
| fn finish(&mut self) { | ||
| self.permit.take(); | ||
| if let Some(finished) = self.finished.take() { | ||
| let _ = finished.send(()); | ||
| } | ||
| } | ||
| } |
Comment on lines
+53
to
+56
| pub(crate) struct RequestBody { | ||
| state: Arc<Mutex<UploadState>>, | ||
| permit: Option<Arc<OwnedSemaphorePermit>>, | ||
| } |
Comment on lines
+368
to
+370
| pub fn with_request_options(mut self, options: ProxyClientOptions) -> Self { | ||
| self.request_slots = Arc::new(Semaphore::new(options.max_in_flight_requests.get())); | ||
| self.options = options; |
Comment on lines
+718
to
+724
| requests_tx | ||
| .send(PendingRequest { | ||
| request: req, | ||
| response_tx, | ||
| deadline, | ||
| permit, | ||
| }) |
Comment on lines
+67
to
+83
| impl ResponseActivity { | ||
| /// Starts idle tracking and wraps the response body to observe completion. | ||
| pub(crate) fn track(&self, response: ProxyResponse) -> ProxyResponse { | ||
| self.0.send_replace(Some(ActiveResponse { | ||
| last_write: Instant::now(), | ||
| body_finished: false, | ||
| })); | ||
| response.map(|inner| { | ||
| let mut body = IdleBody { | ||
| inner, | ||
| activity: Some(self.clone()), | ||
| }; | ||
| if body.inner.is_end_stream() { | ||
| body.finish(); | ||
| } | ||
| body.boxed() | ||
| }) |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This improves concurrency to proxy-client to proxy-server connections.
On HTTP2 (default) requests run concurrently. proxy-server to target service connections still use HTTP1.1 - since we dont use TLS for these and therefore no protocol negotiation. This means we end up with multiple connections between proxy-server and target (usually the same host), multiplexed over a single attested connection over the wire.
On HTTP1.1, requests remain serialized but this PR adds deadlines, cancellation and reconnects.
Limits are configurable: 64 in-flight requests, 60-second request deadlines, and 60-second response idle timeouts, through CLI flags and
ProxyClientOptions.Closes #118