"ThreadError: deadlock; recursive locking" error when recursive lock shouldn't be possible
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
Updated by wanabe (_ wanabe) almost 2 years ago
git bisect shows the problem occurs frequently since r58604.
But I don't know it can occur before the commit.
do_mutex_lock() releases GVL with
The mutex may be released and the thread may be interrupted around the same time.
RUBY_VM_CHECK_INTS_BLOCKING(th->ec) will raise an exception, after locking mutex.