Skip to content

test: wait for transition goroutines to exit#2435

Merged
dunglas merged 1 commit into
mainfrom
fix/test-transition-goroutine-leak
May 19, 2026
Merged

test: wait for transition goroutines to exit#2435
dunglas merged 1 commit into
mainfrom
fix/test-transition-goroutine-leak

Conversation

@dunglas
Copy link
Copy Markdown
Member

@dunglas dunglas commented May 18, 2026

Summary

TestTransitionThreadsWhileDoingRequests spawned 10 transition goroutines that loop calling thread.shutdown() (which reads mainThread.state at https://github.com/php/frankenphp/blob/main/phpthread.go#L133). isDone.Store(true) told them to stop, but the test returned without waiting, so a goroutine could still be inside shutdown() when the next test (TestFinishBootingAWorkerScript) called initPHPThreads and wrote a fresh mainThread.state — producing the macOS -race failure seen in https://github.com/php/frankenphp/actions/runs/26035637665/job/76532863576.

Tracked the transition goroutines with a sync.WaitGroup and wait on it after isDone.Store(true).

TestTransitionThreadsWhileDoingRequests spawned transition goroutines
that read mainThread.state via thread.shutdown(). isDone.Store(true)
signalled them to stop but the test returned without waiting, so they
could still be running when the next test's initPHPThreads wrote a
fresh mainThread.state, producing a -race failure on macOS.
Copilot AI review requested due to automatic review settings May 18, 2026 13:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a race-prone test cleanup path by ensuring transition goroutines exit before the test returns and before global PHP thread state can be reinitialized by subsequent tests.

Changes:

  • Adds a dedicated sync.WaitGroup for transition goroutines.
  • Marks each transition goroutine as done on exit.
  • Waits for transition goroutines after signaling isDone.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@AlliBalliBaba AlliBalliBaba left a comment

Choose a reason for hiding this comment

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

Strange that this only is detected as race on mac.

@dunglas dunglas merged commit 1d8235d into main May 19, 2026
35 checks passed
@dunglas dunglas deleted the fix/test-transition-goroutine-leak branch May 19, 2026 08:11
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.

4 participants