Skip to content

Thread kill does not release lock #6405

@JohnPhillips31416

Description

@JohnPhillips31416

Hit a deadlock where jstack shows a number of threads waiting on a lock but no thread is holding the lock. We were able to reproduce it with the code snippet below. This snippet works (runs indefinitely) on jruby-9.1.17.0 and MRI 2.5.8, but deadlocks on jruby-9.2.9.0 and jruby-9.2.13.0

The suspicion is that the t.kill is killing the thread without releasing the mutex, possible related to this change cc6bf49#diff-7768018ea9b120637b1da8461cb5df2b

def test_it
  mutex = Mutex.new
  sleep_div = 500
  starts = 0
  ends = 0
  2000.times do |i|
    ts = 3.times.map do
      Thread.new do
        sleep(rand / sleep_div)
        mutex.synchronize{ starts += 1; sleep(rand / sleep_div); ends += 1 }
      end
    end
    3.times do
      sleep(rand / sleep_div)
      t = ts.sample
      t.kill
    end
    if i % 10 == 0
      mutex.synchronize do
        puts "iter #{i}, starts: #{starts}, ends: #{ends}"
      end
    end
  end
end

if __FILE__ == $0
  test_it
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions