Skip to content

fix(links): the public link router keeps its connections, checked per request (#559) - #560

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

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

Conversation

@7schmiede

Copy link
Copy Markdown
Member

What and why

The public link router (linkrouter.rs, used by the hub and by a node) opened a new connection to the service for every request and closed it first — the connection-per-request class #556/#557 fixed for forward and the hub's way to its daemons. It was left out there because Dial was both the way to the service and the owner's check that a link is open: a pool by host would have passed a closed link.

  • Dial now only checks: it returns a Way (key = the target, port, tls, and open, the future that connects) and opens nothing. It is called for every request.
  • The router keeps a connpool::Pool by Way::key, uses a kept connection or opens one along open (TLS on top where the service speaks it), resends a request a kept connection handed back unsent, and returns connections through GiveBack. Upgrades keep their own.
  • Hub (publiclinks.rs): route as before, linkrouter::local(port, tls) is now a Way keyed local:<port>:<tls>.
  • Node (node/links.rs): registered host and lease checked as before; the lane daemon's look-up and its tunnel moved into open, keyed lane:<lease>:<port>:<tls>, so the tunnel is reused with its connection.
  • ADR-0091 amended (with the card), ADR-0110's note updated, changelog.

Closes #559

Review card

Approved by the owner in the conversation on 2026-11-17, all three points.

# Category Point Beats Reversing costs
1 trust Every request passes the owner's check before a byte goes to a service; the check opens nothing, and only then a kept or new connection is taken. A pool by host that skips the check for a kept connection Low
2 trust Kept connections belong to the target (hub: port + TLS; node: lease, port, TLS), never to the host name; one no open link leads to idles until the service closes it, unreachable without passing the check. Dropping a link's connections when it closes Low
3 concept The rules of #556: up to 32 idle per target, given back at the end of the answer; upgrades and endless streams keep their own; on a node the lane's tunnel is reused with its connection. Opening the tunnel each time Low

Decided on my own: linkrouter::Dial changes shape (an internal Rust interface); point 2 departs from the issue's own proposal to drop connections when a link closes, since point 1 already protects.

Verified (Windows)

  • linkrouter::tests::the_router_reuses_its_connections_to_a_service: red on main ("20 requests opened 20 connections"), green here (≤ 2). In the same test: after the link closes, a request is a 404 while a connection to the service is kept; opened again, the next request is served without a new connection (proving it was kept).
  • only_what_the_dial_knows_is_served unchanged and green.
  • cargo fmt, cargo clippy -D warnings, cargo test --workspace.
  • Not verified: through a real Cloudflare tunnel; the node's way (lane tunnel) only in CI's remote-lane.

Bug class: connection-per-request.

🤖 Generated with Claude Code

… request (#559)

The router behind a named tunnel (hub and node) opened a new connection to
the service for every request and closed it first, leaving each in
TIME_WAIT for two minutes, the class #556 fixed for `forward`. Its `Dial`
was also the owner's check that a host is open, so a plain pool by host
would have passed a closed link.

`Dial` now only checks and returns a `Way` (target key, port, TLS, and the
future that connects: TCP on the hub, the lane's tunnel on a node). It is
called for every request; only then the router takes a kept connection for
that target from `connpool::Pool`, or opens one, and gives it back through
`GiveBack`. Connections are keyed by the target, never by the host name.

ADR-0091 amended with the review card the owner approved.

Closes #559

Bug-Class: connection-per-request
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@7schmiede
7schmiede merged commit 753685c into main Nov 17, 2026
14 checks passed
@7schmiede
7schmiede deleted the fix/linkrouter-keepalive branch November 17, 2026 19:54
@7schmiede 7schmiede mentioned this pull request Nov 17, 2026
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.

Public link router: reuse connections to the service, without passing a closed link

1 participant