Skip to content

Commit 3b602c9

Browse files
eregonmatzbot
authored andcommitted
[ruby/timeout] Gracefully handle a call to ensure_timeout_thread_created in a signal handler
* Fixes the issue described in ruby/timeout#17 (comment) for TruffleRuby and JRuby. * CRuby is currently unable to use Timeout in a signal handler due to https://bugs.ruby-lang.org/issues/19473. ruby/timeout@7a48e1c079
1 parent 4044188 commit 3b602c9

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

lib/timeout.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ def self.create_timeout_thread
123123

124124
def self.ensure_timeout_thread_created
125125
unless @timeout_thread and @timeout_thread.alive?
126+
# If the Mutex is already owned we are in a signal handler.
127+
# In that case, just return and let the main thread create the @timeout_thread.
128+
return if TIMEOUT_THREAD_MUTEX.owned?
126129
TIMEOUT_THREAD_MUTEX.synchronize do
127130
unless @timeout_thread and @timeout_thread.alive?
128131
@timeout_thread = create_timeout_thread

0 commit comments

Comments
 (0)