Skip to content

Conversation

@spikecurtis
Copy link
Contributor

@spikecurtis spikecurtis commented Sep 16, 2025

fixes coder/internal#966

TestCloserStack_Timeout creates asyncClosers which allow control over the exact timing and order of their close method returning. They also, as a final backstop will throw an error if the test context ends before they are unblocked.

TestCloserStack_Timeout unblocks all asyncClosers in a defer and then ends the test. This defer unblocks the running close goroutines, but does not wait for them to finish. Since the test context is canceled as soon as the test completes, this creates a race condition where the close goroutines can trigger the context cancelled arm of the select statement.

The fix is to both unblock and wait for all close goroutines to complete before ending the test and cancelling the context.

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@spikecurtis spikecurtis marked this pull request as ready for review September 16, 2025 12:44
@spikecurtis spikecurtis merged commit 4fc0093 into main Sep 16, 2025
33 checks passed
@spikecurtis spikecurtis deleted the spike/internal-966-async-closer-race branch September 16, 2025 17:53
@github-actions github-actions bot locked and limited conversation to collaborators Sep 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flake: panic in TestCloserStack_CloseAfterContext

3 participants