Repository navigation
internal/capi: keep connection addresses after half close - #191
Merged
Merged
Conversation
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
force-pushed
the
fix/info-after-half-close
branch
from
November 19, 2026 02:15
df38438 to
9f0909d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #187.
Once both sides of a TCP connection have called
tc_conn_close_write,tc_infoon the side that closed second panics:net.Conn.LocalAddr/RemoteAddrreturn nil after the endpoint leaves the connected state, andInfocalls.String()on them. The guard recovers, but the caller only seesTC_FAILUREplus 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
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.