Skip to content

fix(host): close CONNECT client when the tailnet side ends - #170

Merged
dantraynor merged 1 commit into
mainfrom
fix/connect-tunnel-close
Nov 13, 2026
Merged

dantraynor merged 1 commit into
mainfrom
fix/connect-tunnel-close

Conversation

@dantraynor

Copy link
Copy Markdown
Owner

What

After the upstream-to-client copy in handleConnect ends, close the hijacked client connection when it cannot half-close.

Why

The hijacked conn comes from proxymux.SplitSOCKSAndHTTP, whose connWithOneByte wrapper only promotes net.Conn methods, so the CloseWrite assertion was always false. When the tailnet side closed, the browser was never told and kept reusing a dead keep-alive tunnel until its own timeout, holding a goroutine and a netstack connection.

Fixes #152

How to Test

  • go test -short -race ./... and go vet in host/
  • New TestHandleConnectClosesClientWhenUpstreamCloses fails without the fix (browser read times out) and passes with it

The hijacked connection comes from proxymux, whose wrapper does not
expose CloseWrite, so the half-close after the upstream-to-client copy
never ran. The browser kept a dead tunnel open until its own timeout,
holding a goroutine and a netstack connection. Close the client fully
when it cannot half-close.

Fixes #152
@dantraynor
dantraynor force-pushed the fix/connect-tunnel-close branch from f6aa633 to a33d197 Compare November 13, 2026 07:17
@dantraynor
dantraynor merged commit b944267 into main Nov 13, 2026
19 checks passed
@dantraynor
dantraynor deleted the fix/connect-tunnel-close branch November 13, 2026 07:22
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.

CONNECT tunnels do not tell the browser when the tailnet side closes (proxymux conn has no CloseWrite)

1 participant