Project

General

Profile

Bug #15360

"ThreadError: deadlock; recursive locking" error when recursive lock shouldn't be possible

Added by brockspratlen (Brock Spratlen) about 1 year ago. Updated 3 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-darwin17]
[ruby-core:90170]

Description

I think I've discovered a Ruby bug, possibly introduced in 2.5.

I've attached a reproduction script; running it on Ruby 2.5.0+ (including previews of 2.6.0) seems to always produce a flood of printed ThreadError: deadlock; recursive locking exceptions, even though the reproduction code doesn't appear to do any recursive locking.

Running the same script on Ruby 2.4.5 doesn't produce any ThreadError: deadlock; recursive locking exceptions. I've run the script several times on Ruby 2.4.5, I simply can't reproduce the raising of ThreadError: deadlock; recursive locking with this script on 2.4.5.

Curiously, removing the puts e.class on line 24 causes the bug to go away: ThreadError: deadlock; recursive locking never gets raised regardless of which Ruby version I'm running. Given this oddity, I can't help but think the issue is something around writing to stdout. This change in particular looks suspect: https://bugs.ruby-lang.org/issues/9323

Thank you!
Brock


Files

deadlock_test.rb (556 Bytes) deadlock_test.rb Run with "ruby deadlock_test.rb" brockspratlen (Brock Spratlen), 11/29/2018 06:09 PM

Related issues

Related to Ruby master - Bug #15508: Mutex recursive lock error when combined with Thread#raiseClosedActions
Related to Ruby master - Bug #15645: It is possible to escape `Mutex#synchronize` without releasing the mutexClosedActions

Associated revisions

Revision 52eb4e66
Added by nagachika (Tomoyuki Chikanaga) 4 months ago

merge revision(s) c1d78a7f0ece2004822193a0c1f1fd3dc38c2fdf: [Backport #15360]

    do_mutex_lock: release mutex before checking for interrupts (fixes
     issue 15360)

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@67728 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 67728
Added by nagachika (Tomoyuki Chikanaga) 4 months ago

merge revision(s) c1d78a7f0ece2004822193a0c1f1fd3dc38c2fdf: [Backport #15360]

do_mutex_lock: release mutex before checking for interrupts (fixes
 issue 15360)

Revision 33151275
Added by usa (Usaku NAKAMURA) 3 months ago

merge revision(s) c1d78a7f0ece2004822193a0c1f1fd3dc38c2fdf: [Backport #15360]

    do_mutex_lock: release mutex before checking for interrupts (fixes
     issue 15360)

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_5@67764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 67764
Added by usa (Usaku NAKAMURA) 3 months ago

merge revision(s) c1d78a7f0ece2004822193a0c1f1fd3dc38c2fdf: [Backport #15360]

do_mutex_lock: release mutex before checking for interrupts (fixes
 issue 15360)

History

#1

Updated by brockspratlen (Brock Spratlen) about 1 year ago

  • ruby -v changed from 2.5.3 to ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-darwin17]
#2

Updated by brockspratlen (Brock Spratlen) about 1 year ago

  • Description updated (diff)

Updated by Anonymous 8 months ago

Is there a plan to fix this? We have been noticing this bug occasionally in production.

Updated by wanabe (_ wanabe) 8 months ago

git bisect shows the problem occurs frequently since r58604.
But I don't know it can occur before the commit.

https://bugs.ruby-lang.org/projects/ruby-trunk/repository/trunk/revisions/66489/entry/thread_sync.c#L267
do_mutex_lock() releases GVL with native_sleep(th, timeout).
The mutex may be released and the thread may be interrupted around the same time.
If so, RUBY_VM_CHECK_INTS_BLOCKING(th->ec) will raise an exception, after locking mutex.

#6

Updated by jeremyevans0 (Jeremy Evans) 6 months ago

  • Related to Bug #15508: Mutex recursive lock error when combined with Thread#raise added
#7

Updated by jeremyevans0 (Jeremy Evans) 6 months ago

  • Related to Bug #15645: It is possible to escape `Mutex#synchronize` without releasing the mutex added

Updated by jeremyevans0 (Jeremy Evans) 6 months ago

  • Backport changed from 2.4: UNKNOWN, 2.5: UNKNOWN to 2.4: DONTNEED, 2.5: REQUIRED, 2.6: REQUIRED
  • Status changed from Open to Closed

Updated by nagachika (Tomoyuki Chikanaga) 4 months ago

  • Backport changed from 2.4: DONTNEED, 2.5: REQUIRED, 2.6: REQUIRED to 2.4: DONTNEED, 2.5: REQUIRED, 2.6: DONE

ruby_2_6 r67728 merged revision(s) c1d78a7f0ece2004822193a0c1f1fd3dc38c2fdf.

Updated by usa (Usaku NAKAMURA) 3 months ago

  • Backport changed from 2.4: DONTNEED, 2.5: REQUIRED, 2.6: DONE to 2.4: DONTNEED, 2.5: DONE, 2.6: DONE

ruby_2_5 r67764 merged revision(s) c1d78a7f0ece2004822193a0c1f1fd3dc38c2fdf.

Also available in: Atom PDF