Skip to content

pkg/proc: Fix flaky test on Windows - #4292

Merged
derekparker merged 1 commit into
go-delve:masterfrom
typesanitizer:vg/fix-windows-flake
Mar 25, 2026
Merged

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

Conversation

@typesanitizer

@typesanitizer typesanitizer commented Mar 19, 2026 •

Copy link
Copy Markdown
Contributor

TestWaitFor was flaky on Windows. This seems to be linked to
prefix-based matching, where the fixture process spawned by
one test could be waited upon by another test. Adding a
unique no-op argument to different invocations of the
same fixture binary appears to fix the flakiness issue.

As I understand it, this happens because of the following:

  • Per the docs of WaitForSingleObject,

    Waits until the specified object is in the signaled state or the time-out interval elapses.

    Delve (via stdlib) calls WaitForSingleObject.

  • After the process reaches a signaled state, the test
    which was waiting is unblocked and it proceeds.
    The test executor can switch to the next test
    after the test completes.

  • Concurrent with subsequent test execution, the OS takes
    its own sweet time cleaning the process up from various places.
    (This might be delayed if someone else is holding a handle
    to the process. The Go stdlib closes it's own, I'm not 100%
    sure if it's the only one owning the handle, or whether
    the spawned debugger could still be holding it.)

  • Delve calls CreateToolhelp32Snapshot. This can sometimes
    end up seeing the "not yet fully cleaned up" process.

Claude found this old mailing list thread with a similar issue.
https://microsoft.public.win32.programmer.kernel.narkive.com/k4zy5KXb/waitforsingleobject-and-process-termination

i faced a interesting situation:
I am waiting inside a thread for
a process to exit on WaitForSingleObject().
The process exits, the handle gets signaled
and then i immediatelly call to a
CreateToolhelp32Snapshot(...)
with TH32CS_SNAPPROCESS
and the process is is still listed
in the snapshot. How come?

I'm 80% confident in the above explanation, but it's possible
that I missed something.


I've tested the fix by running the test with -count=100
on Windows.

@aarzilli

Copy link
Copy Markdown
Member

This change makes the test fail on macos.

@typesanitizer

Copy link
Copy Markdown
Contributor Author

@aarzilli, apologies, I missed testing on macOS. I've pushed a change with a fix. Can you take a second look?

Is there a specific reason there are no GitHub Actions for macOS or Linux, only for Windows (that too for arm64 only)?

@aarzilli

Copy link
Copy Markdown
Member

Is there a specific reason there are no GitHub Actions for macOS or Linux, only for Windows (that too for arm64 only)?

They are tested through TeamCity.

Comment thread pkg/proc/proc_test.go Resolved
Comment thread pkg/proc/proc_test.go Resolved
TestWaitFor was flaky on Windows. This seems to be linked to
prefix-based matching, where the fixture process spawned by
one test could be waited upon by another test. Adding a
unique no-op argument to different invocations of the
same fixture binary appears to fix the flakiness issue.

@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

@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 - re-running CI

@derekparker
derekparker merged commit 0355633 into go-delve:master Mar 25, 2026
6 of 7 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