Skip to content

Fix: race condition in Fiber::ExecutionContext::Isolated#wait#15872

Merged
straight-shoota merged 2 commits intocrystal-lang:masterfrom
ysbaddaden:fix/race-condition-in-isolated-context-wait
Jun 6, 2025
Merged

Fix: race condition in Fiber::ExecutionContext::Isolated#wait#15872
straight-shoota merged 2 commits intocrystal-lang:masterfrom
ysbaddaden:fix/race-condition-in-isolated-context-wait

Conversation

@ysbaddaden
Copy link
Collaborator

@ysbaddaden ysbaddaden commented Jun 3, 2025

I don't always enqueue the calling fiber in the wait list, to avoid a race condition, but always suspend it... which leads to the race condition never resuming the fiber 🤦

@ysbaddaden ysbaddaden self-assigned this Jun 3, 2025
@ysbaddaden ysbaddaden added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:multithreading labels Jun 3, 2025
@ysbaddaden ysbaddaden changed the title Fix: race condition in Fiber::ExecutionContext::Isolated#wait Fix: race condition in Fiber::ExecutionContext::Isolated#wait Jun 3, 2025
@ysbaddaden
Copy link
Collaborator Author

The method should finally be correct. I ran into the race while testing #15871, where another thread can finish so fast that it races with the attempt to wait. With this patch, I can't reproduce the bug anymore.

@straight-shoota straight-shoota added this to the 1.17.0 milestone Jun 3, 2025
@straight-shoota straight-shoota moved this from Review to Approved in Multi-threading Jun 3, 2025
@straight-shoota straight-shoota merged commit 3c74705 into crystal-lang:master Jun 6, 2025
36 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in Multi-threading Jun 6, 2025
@ysbaddaden ysbaddaden deleted the fix/race-condition-in-isolated-context-wait branch June 6, 2025 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:multithreading topic:stdlib:runtime

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants