summaryrefslogtreecommitdiff
path: root/lib/timeout.rb
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2025-06-24 22:37:18 +0200
committergit <svn-admin@ruby-lang.org>2025-06-24 20:41:45 +0000
commit3b602c952d1fdebdf15eaa92860d001bd4716f66 (patch)
treee5a8b897e11055907a04efd287c9ad8729ca8d8a /lib/timeout.rb
parent4044188266c6a305bcd72e81c8dc80524c596258 (diff)
[ruby/timeout] Gracefully handle a call to ensure_timeout_thread_created in a signal handler
* Fixes the issue described in https://github.com/ruby/timeout/issues/17#issuecomment-1461498517 for TruffleRuby and JRuby. * CRuby is currently unable to use Timeout in a signal handler due to https://bugs.ruby-lang.org/issues/19473. https://github.com/ruby/timeout/commit/7a48e1c079
Diffstat (limited to 'lib/timeout.rb')
-rw-r--r--lib/timeout.rb3
1 files changed, 3 insertions, 0 deletions
diff --git a/lib/timeout.rb b/lib/timeout.rb
index 4fd1fa46da..f5f232ad2a 100644
--- a/lib/timeout.rb
+++ b/lib/timeout.rb
@@ -123,6 +123,9 @@ module Timeout
def self.ensure_timeout_thread_created
unless @timeout_thread and @timeout_thread.alive?
+ # If the Mutex is already owned we are in a signal handler.
+ # In that case, just return and let the main thread create the @timeout_thread.
+ return if TIMEOUT_THREAD_MUTEX.owned?
TIMEOUT_THREAD_MUTEX.synchronize do
unless @timeout_thread and @timeout_thread.alive?
@timeout_thread = create_timeout_thread