Project

General

Profile

Actions

Bug #18048

closed

Thread#join can break with fiber scheduler unblock fails or blocks.

Added by ioquatix (Samuel Williams) 3 months ago. Updated 21 days ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:104692]

Description

In addition to https://bugs.ruby-lang.org/issues/17666 we found several more cases that need to be addressed.

Fix potential hang when joining threads.

If the thread termination invokes user code after th->status becomes
THREAD_KILLED, and the user unblock function causes that th->status to
become something else (e.g. THREAD_RUNNING), threads waiting in
thread_join_sleep will hang forever. We move the unblock function call
to before the thread status is updated, and allow threads to join as soon
as th->value becomes defined.

Wake up join list within thread EC context. (#4471)

If rb_fiber_scheduler_unblock raises an exception, it can result in a
segfault if rb_threadptr_join_list_wakeup is not within a valid EC. This
change moves rb_threadptr_join_list_wakeup into the thread's top level EC
which initially caused an infinite loop because on exception will retry. We
explicitly remove items from the thread's join list to avoid this situation.

These are already fixed on master branch. Here is a PR for backport: https://github.com/ruby/ruby/pull/4686

Actions

Also available in: Atom PDF