Skip to content

fix: cancel HTTP requests when tracked connections close - #33

Merged
cppla merged 1 commit into
mainfrom
codex/http-close-cancellation
Oct 2, 2026
Merged

cppla merged 1 commit into
mainfrom
codex/http-close-cancellation

Conversation

@cppla

@cppla cppla commented Oct 2, 2026 •

Copy link
Copy Markdown
Owner

Forced HTTP shutdown could close a tracked client socket and release its admission slot while a pipelined request kept waiting for upstream response headers. net/http may already have cached a pipelined byte, so its background reader cannot observe the close.

Bind each accepted HTTP connection context to tracked full close, with cancellation outside locks before tracker release. Registration racing with close returns a canceled child context. Graceful completion, CONNECT buffered bytes, TCP half-close, and shared dialer ownership remain intact.

Validation:

  • Full make check and shuffled make race passed.
  • Real-loopback forced/graceful shutdown and pending CONNECT regressions passed under race; removing only the new binding reproduced the cancellation failure.
  • Lifecycle tests cover close/registration races, parent context ownership, lock/release ordering, and real TCP half-close replies.
  • Local isolated Linux arm64 Docker: 16 key regressions passed, source/module hashes unchanged, container cleaned up.

Local first full attempts also exposed an ignored historical .go diagnostic being compiled by ./...; it was preserved as .go.txt and its overlay corrected before successful complete reruns. This artifact-only correction is not part of the PR.

This change is source-build behavior, not included in v1.0.1. It establishes lifecycle correctness only; custom operations ignoring context remain outside cancellation guarantees. No dependency or release/tag change.

Exact-head validation (022ead1175128071cef0a1892c09404538526c08): CI passed all 11 jobs, CodeQL passed, and Linux netem passed. Container logs confirm integration success and OCI image export; netem logs confirm suite success. All completed on their first attempt.

Merged as f4c8e880225edf873c6c87cf5b748de68cdc8360; local main and origin/main are synchronized with the identical tested tree. Main push CI passed all 11 jobs, CodeQL passed, and Linux netem passed, all on attempt 1. Actual main container/netem logs were verified. All eight new top-level regressions also passed under race ten times on merged main. No release/tag change.

Copilot AI balanced review requested due to automatic review settings October 2, 2026 15:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

No unresolved issues remain, and focused regressions cover cancellation races and preserved connection behavior.

Review effort: Balanced
Findings: None

What changed in this PR

Ensures forced HTTP shutdown cancels pending requests even when pipelining prevents socket-close detection.

Changes:

  • Bind HTTP connection contexts to tracked full closure, canceling before admission-slot release.
  • Add lifecycle and shutdown regressions, including graceful completion and TCP half-close.
  • Document source-build behavior and cancellation limits.
File Description
internal/​proxy/​lifecycle.go Synchronizes context binding and close cancellation.
internal/​proxy/​lifecycle_context_test.go Tests races, cancellation ordering, ownership, and half-close.
internal/​proxy/​http.go Binds accepted HTTP connections to cancellation.
internal/​proxy/​http_shutdown_cancel_test.go Tests forced, graceful, and pending CONNECT shutdown.
docs/​DEPLOYMENT.md Explains shutdown cancellation and release availability.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@cppla
cppla merged commit f4c8e88 into main Oct 2, 2026
15 checks passed
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