Pin npipe round-trip and pipe lifecycle invariants#5216
Merged
Conversation
5 tasks
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5216 +/- ##
==========================================
+ Coverage 67.83% 67.86% +0.02%
==========================================
Files 610 610
Lines 62405 62405
==========================================
+ Hits 42332 42350 +18
+ Misses 16895 16877 -18
Partials 3178 3178 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
a9a8b72 to
fc80b10
Compare
Add three regression tests around the named-pipe transport that the original PR did not cover. None of these reproduce live bugs today; they pin invariants the named-pipe path implicitly relies on so a future change can't silently break them. TestWriteReadServerInfo_NamedPipe (cross-platform) closes the producer/consumer loop for the discovery file: an npipe:// URL written by socketURL must survive WriteServerInfo + ReadServerInfo without being mangled. The individual emit/parse pieces have their own tests; this one pins the seam. TestSetupUnixSocket_NamedPipe_FirstInstanceWins (Windows-only) asserts that two ListenPipe calls on the same name fail the second time. winio sets FILE_FLAG_FIRST_PIPE_INSTANCE so that two thv processes cannot bind the same pipe and race for traffic; if a future winio bump silently relaxed that, this test catches it before the discovery layer does in production. TestCheckHealth_NamedPipe_HungServerCancelsOnContext (Windows-only) covers the StateUnhealthy path: a peer that accepts connections but never responds must not wedge CheckHealth past the caller's context deadline. The existing success and not-found tests don't exercise this case. Co-authored-by: Cursor <cursoragent@cursor.com>
fc80b10 to
f88804b
Compare
Member
aponcedeleonch
left a comment
There was a problem hiding this comment.
Two comments on the new tests.
TestCheckHealth_NamedPipe_HungServerCancelsOnContext registered
t.Cleanup from inside the Accept loop goroutine. t.Cleanup is
documented to be called from the test goroutine; a registration
that lands after the test body returns can panic with "Log in
goroutine after Test has completed" or be silently dropped. The
test happened to work because the dial CheckHealth makes accepts
before the test body returns, but correctness was load-bearing on
that timing.
Pre-register a single t.Cleanup from the test body that closes
every accepted conn under a mutex, and have the goroutine append
to that slice instead of touching t. Listener cleanup runs in
LIFO order before the conn-close, which unblocks the goroutine's
Accept first so the slice is stable by the time we close it.
Drop the dead "if second != nil { Close }" branch in
TestSetupUnixSocket_NamedPipe_FirstInstanceWins: setupUnixSocket
returns (nil, err) on the named-pipe failure path, so the guard
can never be entered. Replace with a comment so the next reader
does not re-introduce it.
Addresses review on #5216.
Co-authored-by: Cursor <cursoragent@cursor.com>
aponcedeleonch
approved these changes
May 8, 2026
Member
aponcedeleonch
left a comment
There was a problem hiding this comment.
Both review comments addressed cleanly. The mutex-guarded slice + pre-registered t.Cleanup matches the suggested rewrite, and the LIFO ordering note in the commit message is a nice touch. LGTM.
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.
Summary
Follow-up to #5201 (review thread). Stacked on
socker-windows; will rebase ontomainonce #5201 merges. Sibling to #5214 and #5215.Adds three regression tests around the named-pipe transport that the original PR did not cover. None reproduce a live bug today; they pin invariants the named-pipe path implicitly relies on so a future change can't silently break them.
TestWriteReadServerInfo_NamedPipe(cross-platform) — closes the producer/consumer loop for the discovery file: annpipe://URL written bysocketURLmust surviveWriteServerInfo+ReadServerInfowithout being mangled. The individual emit/parse pieces have their own tests; this one pins the seam.TestSetupUnixSocket_NamedPipe_FirstInstanceWins(Windows-only) — asserts that twowinio.ListenPipecalls on the same name fail the second time.winiosetsFILE_FLAG_FIRST_PIPE_INSTANCEso twothvprocesses cannot bind the same pipe and race for traffic; if a futurewiniobump silently relaxed that, this test catches it before the discovery layer does in production.TestCheckHealth_NamedPipe_HungServerCancelsOnContext(Windows-only) — covers theStateUnhealthypath: a peer that accepts connections but never responds must not wedgeCheckHealthpast the caller's context deadline. The existing success and not-found tests don't exercise this case.Addresses inline review comments 3201085442 (round-trip), 3201085446 (first-instance-wins), and 3201085449 (hung-peer).
Type of change
Test plan
go test ./pkg/api/... ./pkg/server/discovery/...— green on macOS (round-trip and Unix tests).task lint-fix— 0 issues.GOOS=windows go vetandGOOS=windows go test -c -o /dev/nullfor both packages — both clean.go test -tags windows -run NamedPipeon a Windows host — pending; deferred to a reviewer with a Windows host. The Windows-only tests are guarded by build tags and do not run on macOS / Linux.Does this introduce a user-facing change?
No.
Made with Cursor