Issue #21119: asyncio: Make sure that socketpair() close sockets on error

Close the listening socket if sock.bind() raises an exception.
This commit is contained in:
Victor Stinner 2014-06-04 00:12:28 +02:00
parent 223a624158
commit a9fa2664ab
2 changed files with 26 additions and 15 deletions

View file

@ -51,6 +51,15 @@ class WinsocketpairTests(unittest.TestCase):
self.assertRaises(ValueError,
windows_utils.socketpair, proto=1)
@mock.patch('asyncio.windows_utils.socket')
def test_winsocketpair_close(self, m_socket):
m_socket.AF_INET = socket.AF_INET
m_socket.SOCK_STREAM = socket.SOCK_STREAM
sock = mock.Mock()
m_socket.socket.return_value = sock
sock.bind.side_effect = OSError
self.assertRaises(OSError, windows_utils.socketpair)
self.assertTrue(sock.close.called)
class PipeTests(unittest.TestCase):