Project

General

Profile

Bug #15385

Ruby process hang in ensure

Added by pawelpacana (Paweł Pacana) almost 2 years ago. Updated over 1 year ago.

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

Description

While playing with mutation testing of my code I've found a weird mutation that hangs Ruby process. The isolated code which triggers this freeze is:

require 'timeout'

puts Process.pid

def raise_before_returning
  raise
  []
end

def doh
  value = raise_before_returning
ensure
  # p value # <-- that unblocks it
  value if nil
end

Timeout.timeout(3) do
  doh
end
  1. Timeout is unnecessary and was added to illustrate that it has no effect to interrupt hanged process.
  2. Process.pid is printed for convenience to kill hanged process.
  3. Printing value in ensure changes behavior, there is no hang when encountering value if nil below.

I've also checked ruby 2.6.0preview3 (2018-11-06 trunk 65578) [x86_64-darwin18] and the problem persists.


Files

reproduce.rb (216 Bytes) reproduce.rb reproduction script pawelpacana (Paweł Pacana), 12/06/2018 01:42 AM

Related issues

Related to Ruby master - Bug #14897: Unexpected behavior of `if` in specific codeClosedActions

Also available in: Atom PDF