From 567e312d1f56c27ecb4fa20deac4311f05ee5507 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Thu, 8 Aug 2019 15:44:26 -0700 Subject: [PATCH] Do not raise an exception on a closed DRb socket This rescues some exceptions that could happen with a closed or shutdown DRb socket. This can prevent the server from exiting if an client socket is closed directly after it is accepted. Fixes [Bug #8039] --- lib/drb/drb.rb | 2 ++ test/drb/test_drb.rb | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/drb/drb.rb b/lib/drb/drb.rb index 25642dd939..9b4d675096 100644 --- a/lib/drb/drb.rb +++ b/lib/drb/drb.rb @@ -1024,6 +1024,8 @@ module DRb def set_sockopt(soc) # :nodoc: soc.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) + rescue IOError, Errno::ECONNRESET, Errno::EINVAL + # closed/shutdown socket, ignore error end end diff --git a/test/drb/test_drb.rb b/test/drb/test_drb.rb index 4e8f5cb0ec..b4399573aa 100644 --- a/test/drb/test_drb.rb +++ b/test/drb/test_drb.rb @@ -327,4 +327,19 @@ class TestBug4409 < Test::Unit::TestCase end end +class TestDRbTCP < Test::Unit::TestCase + def test_immediate_close + server = DRb::DRbServer.new('druby://:0') + host, port, = DRb::DRbTCPSocket.send(:parse_uri, server.uri) + socket = TCPSocket.open host, port + socket.shutdown + socket.close + client = DRb::DRbTCPSocket.new(server.uri, socket) + assert client + client.close + server.stop_service + server.thread.join + end +end + end