Skip to content

fix(windows): keep a handoff whose sender closed before the owner listened - #2393

Merged
houko merged 3 commits into
nsgo-dev:mainfrom
Laotree:fix/instance-handoff-wait
Nov 26, 2026
Merged

houko merged 3 commits into
nsgo-dev:mainfrom
Laotree:fix/instance-handoff-wait

Conversation

@Laotree

@Laotree Laotree commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

TestInstanceHandsOffByKey failed on a Windows runner with key "two" did not receive its files after a fixed 3-second wait (run 45628280474, job 139254247142). The whole step took 4.4 seconds, so the runner was not slow: the handoff was lost.

The cause is a race in serve (internal/platform/windows/instance.go). serve calls CreateNamedPipeW and then ConnectNamedPipe; sendInstance connects, writes and closes in one go. If the sender finishes between those two calls, ConnectNamedPipe fails with ERROR_NO_DATA (232), not ERROR_PIPE_CONNECTED (535). serve only accepted 535, so it skipped ReadFile and dropped the message, while the sender had already reported success. In a real app this silently loses the files and links a second launch hands over.

  • serve now treats ERROR_NO_DATA as connected and reads the buffered message, as CPython's multiprocessing PipeListener does (bpo-14725). The per-connection logic moves into receiveInstance and pipe creation into createInstancePipe, without other behavior changes.
  • New TestInstanceReceivesAClosedSender reproduces the race deterministically: it creates the pipe, runs sendInstance to completion, then calls receiveInstance and checks the message arrives.
  • TestInstanceHandsOffByKey waits up to a fixed 30 seconds instead of 3. The earlier revision of this PR waited for the rest of t.Deadline(); on the host go tool nsgo test passes no -timeout, so that was go test's 10-minute default, not three minutes, and a lost message would have hung the job for about ten minutes.

Targets

  • Shared code (core, base, ui, tsx, the nsgo tool)
  • macOS
  • iOS
  • tvOS
  • watchOS
  • Android
  • Windows
  • Linux
  • Web
  • Mini programs
  • Docs or website only

Screenshots

None; nothing visible changes.

Verification

  • go tool nsgo check -target windows ./internal/platform/windows passes (windows_arm64 and windows_x64).
  • The Windows test binary cross-compiles; the tests themselves run in this PR's windows job (go tool nsgo test -run '^TestInstance' ./internal/platform/windows).

Checklist

  • The title is a Conventional Commit; a squash merge uses it as the commit subject.
  • Docs whose facts change are updated, and a capability users can see has a line in a changelog.d/ fragment, not in CHANGELOG.md.
  • New third-party code, assets and dependencies name their source and license. None are added.

The keyed-handoff test failed when its delivery took more than a fixed
three seconds, which only says the runner was loaded: the sender writes
to the pipe and returns, and the owner delivers on its own goroutine.
Wait until the delivery arrives, bounded by what is left of the test's
deadline, so a loaded runner does not fail a correct handoff.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A second launch connects, writes and closes in one go. When it finishes before the owner's serve goroutine calls ConnectNamedPipe, the call fails with ERROR_NO_DATA rather than ERROR_PIPE_CONNECTED, and serve skipped the read, dropping the launch's files and links while the sender reported success. Treat ERROR_NO_DATA as connected and read the buffered message, as CPython's multiprocessing does (bpo-14725).
Add a deterministic test that runs sendInstance to completion before receiveInstance calls ConnectNamedPipe, and bound the handoff wait at 30 seconds instead of the rest of the test deadline, so a lost message fails quickly.
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Nov 26, 2026
@houko houko changed the title test(windows): wait for a handoff with the test's budget fix(windows): keep a handoff whose sender closed before the owner listened Nov 26, 2026
@github-actions github-actions Bot added the bug Something isn't working label Nov 26, 2026
@houko
houko merged commit 85971bc into nsgo-dev:main Nov 26, 2026
41 of 42 checks passed
@Laotree
Laotree deleted the fix/instance-handoff-wait branch November 26, 2026 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation size/S Windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants