Ruby process hang in ensure
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
Timeoutis unnecessary and was added to illustrate that it has no effect to interrupt hanged process.
Process.pidis printed for convenience to kill hanged process.
valuein ensure changes behavior, there is no hang when encountering
value if nilbelow.
I've also checked
ruby 2.6.0preview3 (2018-11-06 trunk 65578) [x86_64-darwin18] and the problem persists.
Updated by pawelpacana (Paweł Pacana) about 4 years ago
Updated by nobu (Nobuyoshi Nakada) about 4 years ago
- Status changed from Open to Closed
Applied in changeset trunk|r66326.
Fix infinite loop by ensure
- compile.c (iseq_insert_nop_between_end_and_cont): insert nop so
that the end of rescue and continuing points are not same, to
get rid of infinite loop. [Bug #15385]