Skip to content

Conversation

@bmansoob
Copy link
Contributor

Fixes the case when process A starts the background thread and process B is forked from process A. In this case, the old code would not recreate the thread because the thread variable is still there but the thread itself is dead.

We see this a lot in pitchfork because workers are forked from mold, which I believe/understand is selected from a worker too.

Copy link
Member

@dalehamel dalehamel left a comment

Choose a reason for hiding this comment

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

solid debugging of a gnarly edge case 👏

end

def process_queue_thread
@process_queue_thread ||= Thread.new do
Copy link
Member

Choose a reason for hiding this comment

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

so this line here is the root of the bug right? This variable is bound already, but the thread is dead, so we call this method but it returns and a new thread is never started

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes

assert(th.alive?)
end

test "process_queue_thread is recreated on enqueue if stopped" do
Copy link
Member

Choose a reason for hiding this comment

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

I assume this tests fails on the old code right? Just to be 100% sure it's a good regression test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I tested that. Had to add th.join as kill is not instant and the failure was flaky.

@bmansoob bmansoob marked this pull request as ready for review January 8, 2025 18:52
@bmansoob bmansoob requested a review from gmcgibbon January 8, 2025 18:52
Copy link
Member

@manuelfelipe manuelfelipe left a comment

Choose a reason for hiding this comment

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

thanks for the fix and the troubleshooting efforts. Fix makes sense when considering our forking strategy

@bmansoob
Copy link
Contributor Author

tested this in production - fix works.

@bmansoob bmansoob merged commit e9a6a80 into main Jan 20, 2025
7 checks passed
@bmansoob bmansoob deleted the fix-background-thread branch January 20, 2025 17:00
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.

3 participants