Skip to content

pkg/proc: Fix flakiness in TestWaitFor - #4306

Merged
derekparker merged 1 commit into
go-delve:masterfrom
typesanitizer:vg/fix-windows-flake-2
Apr 23, 2026
Merged

derekparker merged 1 commit into
go-delve:masterfrom
typesanitizer:vg/fix-windows-flake-2

Conversation

@typesanitizer

Copy link
Copy Markdown
Contributor

TestWaitFor could have the following sequence of events:

  1. cmd.Start() is called.
  2. The process is started in the kernel.
  3. CreateToolhelp32Snapshot (inside waitForSearchProcess) sees
    the process and returns from native.WaitFor.
  4. The test immediately deferences cmd.Process, but cmd.Process
    has not been assigned yet in cmd.Start() -> nil panic.

This patch fixes the issue by introducing a channel that is
written to from testWaitForSetup() after cmd.Start() returns.
Unlike the mutex + boolean, this channel can be waited upon
without spinning, and only then cmd.Process is read inside
the test code.

Comment thread pkg/proc/proc_test.go Resolved
Comment thread pkg/proc/proc_test.go Resolved
Comment thread pkg/proc/proc_test.go Resolved
TestWaitFor could have the following sequence of events:
1. cmd.Start() is called.
2. The process is started in the kernel.
3. CreateToolhelp32Snapshot (inside waitForSearchProcess) sees
   the process and returns from native.WaitFor.
4. The test immediately deferences cmd.Process, but cmd.Process
   has not been assigned yet in cmd.Start() -> nil panic.

This patch fixes the issue by introducing a channel that is
written to from testWaitForSetup() _after_ cmd.Start() returns.
Unlike the mutex + boolean, this channel can be waited upon
without spinning, and only then cmd.Process is read inside
the test code.
@typesanitizer
typesanitizer force-pushed the vg/fix-windows-flake-2 branch from 6ec1390 to 236ce9d Compare April 14, 2026 17:46

@aarzilli aarzilli left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@typesanitizer

Copy link
Copy Markdown
Contributor Author

@aarzilli sorry, I don't have merge access, can you merge the PR for me? Is there something else you'd like me to do before merging?

@derekparker derekparker left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@derekparker
derekparker merged commit 08ef5f3 into go-delve:master Apr 23, 2026
3 of 4 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.

3 participants