Skip to content

Commit 3c74705

Browse files
authored
Fix: race condition in Fiber::ExecutionContext::Isolated#wait (#15872)
We 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.
1 parent b987c1f commit 3c74705

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/fiber/execution_context/isolated.cr

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,11 @@ module Fiber::ExecutionContext
191191
def wait : Nil
192192
if @running
193193
node = Fiber::PointerLinkedListNode.new(Fiber.current)
194-
195-
@mutex.synchronize do
194+
running = @mutex.synchronize do
196195
@wait_list.push(pointerof(node)) if @running
196+
@running
197197
end
198-
199-
Fiber.suspend
198+
Fiber.suspend if running
200199
end
201200

202201
if exception = @exception

0 commit comments

Comments
 (0)