Skip to content

Commit 280eeb5

Browse files
committed
[test] add test for accept on closed server
1 parent b84d783 commit 280eeb5

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

test/jruby/test_io.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,4 +651,35 @@ def out_stream.read(*n)
651651
assert_equal before, after, "no wrappers should have been registered"
652652
end
653653

654+
# https://github.com/jruby/jruby/issues/9324
655+
def test_accept_on_closed_server_raises_ioerror
656+
require 'socket'
657+
658+
# Concurrent threads create timing pressure needed to hit the race between one accept returning and the next start.
659+
500.times do
660+
tcp = TCPServer.new("127.0.0.1", 0)
661+
port = tcp.connect_address.ip_port
662+
663+
thread = Thread.new do
664+
Thread.current.abort_on_exception = false
665+
Thread.current.report_on_exception = false
666+
loop do
667+
c = tcp.accept
668+
c.close
669+
end
670+
rescue IOError, Errno::EBADF, Errno::EINVAL, Errno::ECONNABORTED, Errno::ENOTSOCK, Errno::ECONNRESET
671+
# expected on shutdown — before the fix, NullPointerException/AssertionError escapes here
672+
end
673+
674+
10.times { Thread.new { begin; TCPSocket.new("127.0.0.1", port).close; rescue; end } }
675+
Thread.pass
676+
tcp.close rescue nil
677+
678+
thread.join(2)
679+
thread.kill if thread.alive?
680+
end
681+
# If we reach here, no AssertionError killed the process
682+
assert true
683+
end
684+
654685
end

0 commit comments

Comments
 (0)