Bug #15509
closedTCPServer#accept isn't interrupted
Description
This is another issue I noticed with Eventbox:
This script tries to stop TCPServer#accept
with Thread#raise
:
require "socket"
Thread.abort_on_exception = true
class Stop < RuntimeError
end
serv = TCPServer.new("localhost", 12345)
th = Thread.handle_interrupt(Exception => :never) do
Thread.new do
begin
Thread.handle_interrupt(Stop => :on_blocking) do
# sleep # sleep is aborted
serv.accept # but accept isn't
end
rescue Stop
end
end
end
th.raise Stop
th.join
serv.close
The program freezes and if stopped per CTRL-C the output looks similar to:
$ ruby -d --disable-gems no-interrupt-while-accept.rb
^CException `Interrupt' at no-interrupt-while-accept.rb:23 -
Exception `Stop' at no-interrupt-while-accept.rb:15 - Stop
Traceback (most recent call last):
1: from no-interrupt-while-accept.rb:23:in `<main>'
no-interrupt-while-accept.rb:23:in `join': Interrupt
The debug output shows, that the Stop
exception is delivered after the Interrupt
exception has been delivered to the main thread. However it should be delivered immediately, since it's a blocking operation. In contrast sleep
is aborted as expected.
This issue is present on all older MRI versions. However it doesn't appear on JRuby-9.2.5.0.
Updated by jeremyevans0 (Jeremy Evans) over 5 years ago
- Status changed from Open to Closed
This problem appears fixed in 2.6.4 and 2.7.0-preview1 in my environment (OpenBSD-amd64). It still occurs in 2.5.6. If it still occurs for you in 2.6.4, please reopen.
Updated by larskanis (Lars Kanis) almost 5 years ago
- Status changed from Closed to Open
Thank you @jeremyevans0 (Jeremy Evans) for checking this! Unfortunately it still fails on Linux. I tried the following recent ruby versions and they all block infinitely:
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux]
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]
ruby 2.5.7p206 (2019-10-01 revision 67816) [x86_64-linux]
It however stops as expected on Windows:
$ ruby -v
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [i386-mingw32]
$ ruby -d --disable-gems bug_15509.rb
Exception `Stop' at bug_15509.rb:14 - Stop
Updated by larskanis (Lars Kanis) over 3 years ago
The problem is fixed in ruby-3.0.0 on x86_64-linux and on ruby-head, probably as part of the async improvements. So the issue can be closed.
Updated by jeremyevans0 (Jeremy Evans) over 3 years ago
- Status changed from Open to Closed