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