Skip to content

fix(static): a forward keeps its connections to the target (#556) - #557

Merged
7schmiede merged 1 commit into
mainfrom
fix/forward-keepalive
Nov 17, 2026
Merged

7schmiede merged 1 commit into
mainfrom
fix/forward-keepalive

Conversation

@7schmiede

Copy link
Copy Markdown
Member

What and why

forward on a static service (0.49.1) opened a new connection to the target for every request and closed it first: each left a socket in TIME_WAIT for two minutes, and an end-to-end suite (4 workers, ~1000 tests) drained Windows' ephemeral ports (ERR_ADDRESS_IN_USE, 502). The "no pool" was my decision while building ADR-0110, and wrong.

  • devstack_node::connpool: Pool<K, B> keeps idle HTTP/1.1 connections per key (up to 32), send resends on a new connection when a kept one was closed while idle, and GiveBack is the answer's body that returns the connection once read to its end — including a body of known length, which hyper does not poll past its last frame (the first version missed that; the count test caught it).
  • staticsrv: each forward target uses the pool. Upgrades (WebSocket) and streams that do not end (SSE) keep their own connection.
  • Sibling of the same class: the hub's way to its daemons (daemon_send) used a connection per request too; it now uses the same pool by daemon port, and its resend logic treats a kept connection the daemon closed while idle as unsent.
  • Left as it is, on purpose: the public link router (linkrouter.rs) — its Dial is also its check that a host is still open, so a kept connection would pass a link its owner closed; the service proxy (proxy.rs) — already pools, tied to its drain.
  • ADR-0110 amended; changelog.

Closes #556

Verified (Windows)

connections to the target TIME_WAIT to the target
0.49.1, 2000 requests 4 at a time through serve-static --forward 2001 2001
this branch, same run 4 0
  • staticsrv::tests::a_forward_reuses_its_connections_to_the_target: red on main ("30 requests one after another opened 30 connections"), green here, also 4 at a time (≤ 8).
  • daemon_send_tests::the_hub_reuses_its_connections_to_a_daemon: red with reuse switched off ("20 requests opened 20 connections"), green here; the hub's resend tests unchanged and green.
  • cargo fmt, cargo clippy -D warnings, cargo test --workspace.
  • Not run: the full downstream suite; the hub change was not watched in a running hub (unit tests against a real HTTP server only).

Bug class: connection-per-request.

🤖 Generated with Claude Code

A static service's forward opened a new connection to the target for every
request and closed it first, so each left a socket in TIME_WAIT for two
minutes; an end-to-end suite drained Windows' ephemeral ports, and pages
and API calls failed with ERR_ADDRESS_IN_USE or 502.

devstack_node::connpool keeps idle HTTP/1.1 connections per key and gives
a connection back once its answer is read to its end (GiveBack, which also
handles a body of known length that hyper does not poll past its last
frame). The forward uses it per target, and so does the hub's way to its
daemons, which had the same flaw. Upgrades (WebSocket) and streams that do
not end (SSE) keep their own connection. 2000 requests four at a time now
open 4 connections to the target instead of 2001.

The public link router keeps a connection per request: its dial is also
its check that a link is still open (ADR-0110 amendment).

Closes #556

Bug-Class: connection-per-request
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@7schmiede
7schmiede merged commit c8bbd1f into main Nov 17, 2026
14 checks passed
@7schmiede
7schmiede deleted the fix/forward-keepalive branch November 17, 2026 18:48
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.

forward: reuse connections to the target (keep-alive); a long run exhausts ephemeral ports on Windows

1 participant