Skip to content

internal/capi: keep connection addresses after half close - #191

Merged
bradfitz merged 1 commit into
tailscale:mainfrom
CJstate:fix/info-after-half-close
Nov 19, 2026
Merged

bradfitz merged 1 commit into
tailscale:mainfrom
CJstate:fix/info-after-half-close

Conversation

@CJstate

@CJstate CJstate commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Fixes #187.

Once both sides of a TCP connection have called tc_conn_close_write, tc_info on the side that closed second panics: net.Conn.LocalAddr / RemoteAddr return nil after the endpoint leaves the connected state, and Info calls .String() on them. The guard recovers, but the caller only sees TC_FAILURE plus a goroutine dump.

Capture the local and remote address strings when the connection is created and serve those from the handle. The addresses are fixed for the lifetime of the connection, so this also avoids repeated address lookups.

Verification

  • Added TestInfoAfterHalfClose, which reproduces the panic on the unmodified tree (RED) and passes with the fix (GREEN).
  • go test ./internal/capi -count=1: ok.
  • go vet ./internal/capi: ok.

A netstack TCP conn returns a nil RemoteAddr once its endpoint reaches
CLOSED. If both sides write-close, the side that closes second gets
there while its handle is still open, and Info then panicked calling
String on the nil address, taking down the host process.

Record the addresses when the connection is published and have Info
report those instead.

Co-authored-by: Brad Fitzpatrick <bradfitz@tailscale.com>
@bradfitz
bradfitz force-pushed the fix/info-after-half-close branch from df38438 to 9f0909d Compare November 19, 2026 02:15
@bradfitz
bradfitz merged commit c14b171 into tailscale:main Nov 19, 2026
10 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.

internal/capi: tc_info panics on a TCP connection for the side that write closes second

2 participants