Skip to content

Fix race condition in rake parse:topgems#3648

Merged
kddnewton merged 1 commit intoruby:mainfrom
byroot:fix-topgem-deadlock
Sep 15, 2025
Merged

Fix race condition in rake parse:topgems#3648
kddnewton merged 1 commit intoruby:mainfrom
byroot:fix-topgem-deadlock

Conversation

@byroot
Copy link
Member

@byroot byroot commented Sep 15, 2025

block.call(queue.shift) until queue.empty? isn't thread safe.

If there is one element left in the queue, two or more thread may see queue.empty? return false and call the blocking shift ending in a deadlock.

The proper way to synchronize threads with a queue is to close the queue once no more elements need to be added.

This should fix the occasional fatal: No live threads left. Deadlock? (fatal) failures on CI. e.g. https://github.com/ruby/prism/actions/runs/17697479732/job/50298732002?pr=3644#step:5:43

`block.call(queue.shift) until queue.empty?` isn't thread safe.

If there is one element left in the queue, two or more thread may
see `queue.empty?` return `false` and call the blocking `shift`
ending in a deadlock.

The proper way to synchronize threads with a queue is to close the
queue once no more elements need to be added.

This should fix the occasional `fatal: No live threads left. Deadlock? (fatal)`
failures on CI.
@byroot byroot requested a review from kddnewton September 15, 2025 08:49
Copy link
Collaborator

@kddnewton kddnewton left a comment

Choose a reason for hiding this comment

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

Thank you!

@kddnewton kddnewton merged commit 25c7cfd into ruby:main Sep 15, 2025
60 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.

2 participants