Skip to content

fix(h1): close the connection after a refused CONNECT - #8

Merged
shaneutt merged 1 commit into
praxis-proxy:mainfrom
esnible:fix/connect-refusal-close
Nov 3, 2026
Merged

shaneutt merged 1 commit into
praxis-proxy:mainfrom
esnible:fix/connect-refusal-close

Conversation

@esnible

@esnible esnible commented Nov 3, 2026

Copy link
Copy Markdown
Member

What

Close the downstream connection after any final non-2xx response to CONNECT. In prepare_response_header, this adds an else if to the CONNECT 2xx branch that calls set_keepalive(None) before the Connection header value is chosen. A 403/407 to CONNECT is now always sent with Connection: close, and reuse() returns None.

Follow-up to #7. The review is on that PR.

Why

#7 keeps early tunnel bytes (bytes the client sends after the CONNECT head, before the response) out of the next request, but only when they arrive in a later read. The idle branch of read_body_or_idle stashes them and turns keepalive off.

When those bytes arrive in the same read as the CONNECT head, init_content_length_owned(0, preread_body) puts them in overread, and the stash never runs. Keepalive stays on, and on a refusal with pipelining enabled, reuse() passes the overread to the next session as pipelined_prefix:

CONNECT pingora.org:443 HTTP/1.1\r\nHost: pingora.org:443\r\n\r\nGET /x HTTP/1.1\r\nHost: a\r\n\r\n   (one read)
-> 407, Content-Length: 0
-> reuse() == Some(prefix = "GET /x HTTP/1.1...")

A front end that treats bytes after a CONNECT as opaque tunnel data would see them parsed here as an HTTP request. Without pipelining (the default), reuse() already closes because of the overread, but the refusal still said Connection: keep-alive.

Turning keepalive off for every refused CONNECT makes the existing comment ("A refused CONNECT closes the connection") true no matter how the bytes were read. The cost is one new connection for a client that retries after a 407, which a client sees Connection: close for anyway.

Testing

  • New same_read_early_bytes_close_a_refused_connect: same read + set_pipelining_enabled(true) + 407, asserts !will_keepalive() and reuse() is None. It fails without the fix.
  • cargo test -p quixotic-plecostomus-core --lib: 587 passed.
  • cargo test -p quixotic-plecostomus-proxy --lib: 77 passed. --test test_basic connect: 12 passed.
  • cargo fmt --all -- --check and cargo clippy -p quixotic-plecostomus-core --all-targets -- -D warnings: clean.

Assisted-By: Claude Code

Early tunnel bytes that arrive in the same read as the CONNECT head go
to overread when the empty request body is framed, not through the idle
stash. The stash is what turns keepalive off, so a refused CONNECT left
the connection reusable. With pipelining enabled, reuse() then passed
those bytes on as the next request, so client data meant as opaque
tunnel bytes was parsed as an HTTP request after a 403 or 407.

Disable keepalive for every final non-2xx response to CONNECT, so the
refusal is sent with Connection: close and the connection is never
reused, whichever read the early bytes came in.

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Ed Snible <snible@us.ibm.com>
@coderabbitai

coderabbitai Bot commented Nov 3, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Central YAML; Path: .coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 7957a4f2-0e24-4853-a64d-b8568dfdab89

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

@shaneutt
shaneutt requested a review from araujof November 3, 2026 20:10
@shaneutt shaneutt self-assigned this Nov 3, 2026
@shaneutt shaneutt moved this from Next to Review in Core Proxy Nov 3, 2026
@shaneutt
shaneutt merged commit a9d2503 into praxis-proxy:main Nov 3, 2026
7 checks passed
@github-project-automation github-project-automation Bot moved this from Review to Done in Core Proxy Nov 3, 2026
@esnible
esnible deleted the fix/connect-refusal-close branch November 3, 2026 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants