Bug #17617
closedWhen a Ractor's incoming port is closed, Ractor.receive_if does not raise Ractor::ClosedError, but instead blocks indefinitely
Description
If Ractor#close_incoming is called on a Ractor, any pending Ractor.receive call will raise Ractor::ClosedError. However, any pending Ractor.receive_if call will not; instead, it never returns.
r1 = Ractor.new do Ractor.receive rescue => e e end r1.close_incoming result = r1.take puts "**** taken: #{result}" # displays the Ractor::ClosedError r2 = Ractor.new do Ractor.receive_if { true } puts "**** never reaches here" rescue => e puts "**** never reaches here" e end r2.close_incoming puts "**** hangs here..." r2.take puts "**** never reaches here" This was tested against both 3.0.0 and 3.1.0 head, with the same result.
% ruby -v ruby 3.1.0dev (2021-02-09T13:22:37Z master e7a831de8e) [x86_64-darwin20] % ruby -v ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin20 I have also tried including sleep statements to force the Ractor.receive_if to execute both before and after the Ractor#close_incoming call. The result is the same either way. receive_if hangs regardless of whether the incoming port is already closed when receive_if is invoked, or whether the port is closed while the receive_if is already blocking.
Updated by mame (Yusuke Endoh) about 4 years ago
- Assignee set to ko1 (Koichi Sasada)
Updated by dazuma (Daniel Azuma) about 2 years ago
- ruby -v changed from ruby 3.1.0dev (2021-02-09T13:22:37Z master e7a831de8e) [x86_64-darwin20] to ruby 3.3.0dev (2023-11-13T21:00:10Z master e8ab3f7010) [x86_64-darwin23]
Retested, still reproduces on 3.2.2 and 3.3.0-dev as of 2023 Nov 13.
Updated by hsbt (Hiroshi SHIBATA) over 1 year ago
- Status changed from Open to Assigned
Updated by jhawthorn (John Hawthorn) 6 months ago
- Assignee changed from ko1 (Koichi Sasada) to ractor
Updated by jhawthorn (John Hawthorn) 5 months ago
- Status changed from Assigned to Closed
receive_if has been removed with the introduction of Ractor::Port, so this should no longer be an issue