Skip to content

Thread not killed after calling #kill #6188

@wjordan

Description

@wjordan

This simple script demonstrates an edge-case where Thread#kill does not kill a thread as expected on JRuby. It intermittently hangs on JRuby but reliably runs on other Ruby implementations (MRI, TruffleRuby):

Thread.new {sleep rescue sleep}.
  tap {|t| t.raise 'Error'}.
  tap(&:kill).
  tap(&:join)

Some notes:

  • It seems to be a race condition / timing issue related to the rescue operation?
  • If I add a sleep 0.1 after t.raise 'Error', the script passes
  • If I change t.raise 'Error' to t.raise RuntimeError.new (or t.raise), the script passes

Environment Information
JRuby version 9.2.11.1 on Ubuntu 18.04

jruby 9.2.11.1 (2.5.7) 2020-03-25 b1f55b1a40 Java HotSpot(TM) 64-Bit Server VM 25.131-b11 on 1.8.0_131-b11 [linux-x86_64]
Linux wjordan 4.15.0-88-generic #88-Ubuntu SMP Tue Feb 11 20:11:34 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions