tailchrome icon indicating copy to clipboard operation
tailchrome copied to clipboard

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

Open lucastanzani opened this issue 1 month ago • 0 comments

Version: v0.1.15, host/proxy.go:567-586. Found by reading the code, not reproduced.

The CONNECT handler copies both directions and half-closes with CloseWrite() when the other side supports it:

go func() {
    io.Copy(client, upstream)
    if cw, ok := client.(interface{ CloseWrite() error }); ok {
        cw.CloseWrite()
    }
    done <- struct{}{}
}()

client is the hijacked connection, which comes from the listener returned by proxymux.SplitSOCKSAndHTTP (proxy.go:50). In tailscale.com/net/proxymux, that listener hands out *connWithOneByte, a struct that embeds the net.Conn interface, so only net.Conn's methods are promoted and the CloseWrite type assertion is always false. When the tailnet side closes, nothing is signalled to the browser; the handler then waits on the other goroutine until the browser closes the connection on its own.

What we would expect from this: a pooled keep-alive connection to a tailnet server that went away (or after an exit-node switch) stays open from the browser's point of view, and the next request on it hangs until the browser's own timeout, while a goroutine and a netstack connection are held.

Suggestion: when the upstream-to-client copy ends and the client cannot half-close, close the client connection (or unwrap to the underlying *net.TCPConn before the assertion).

lucastanzani avatar Oct 21 '26 14:10 lucastanzani