diff options
author | nagachika <nagachika@ruby-lang.org> | 2022-11-13 11:18:27 +0900 |
---|---|---|
committer | nagachika <nagachika@ruby-lang.org> | 2022-11-13 11:18:27 +0900 |
commit | 61818395312c6e765dc8e7be8bf32cd2c82fec39 (patch) | |
tree | 9080b5d5dd29ac71849c5ea5145252bd2111f240 /test | |
parent | db1aa39ffcaa5b9f062639eb30c76959f4607a8e (diff) |
merge revision(s) eacedcfe44a0ae22bf54ddb7df193c48d4c857c6: [Backport #19105]
mutex: Raise a ThreadError when detecting a fiber deadlock (#6680)
[Bug #19105]
If no fiber scheduler is registered and the fiber that
owns the lock and the one that try to acquire it
both belong to the same thread, we're in a deadlock case.
Co-authored-by: Jean Boussier <byroot@ruby-lang.org>
---
test/fiber/test_mutex.rb | 22 +++++++++++++++++++++-
thread_sync.c | 4 ++++
2 files changed, 25 insertions(+), 1 deletion(-)
Diffstat (limited to 'test')
-rw-r--r-- | test/fiber/test_mutex.rb | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/test/fiber/test_mutex.rb b/test/fiber/test_mutex.rb index b0655f06a5..449c49f38b 100644 --- a/test/fiber/test_mutex.rb +++ b/test/fiber/test_mutex.rb @@ -194,7 +194,7 @@ class TestFiberMutex < Test::Unit::TestCase end def test_mutex_deadlock - error_pattern = /No live threads left. Deadlock\?/ + error_pattern = /lock already owned by another fiber/ assert_in_out_err %W[-I#{__dir__} -], <<-RUBY, ['in synchronize'], error_pattern, success: false require 'scheduler' @@ -217,4 +217,24 @@ class TestFiberMutex < Test::Unit::TestCase thread.join RUBY end + + def test_mutex_fiber_deadlock_no_scheduler + thr = Thread.new do + loop do + sleep 1 + end + end + + mutex = Mutex.new + mutex.synchronize do + error = assert_raise ThreadError do + Fiber.new do + mutex.lock + end.resume + end + assert_includes error.message, "deadlock; lock already owned by another fiber belonging to the same thread" + end + ensure + thr&.kill&.join + end end |