mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-43253: Don't call shutdown() for invalid socket handles (GH-31892)
(cherry picked from commit 70155412f1
)
Co-authored-by: Maximilian Hils <git@maximilianhils.com>
This commit is contained in:
parent
91dfa917e5
commit
64a68c39cb
3 changed files with 10 additions and 1 deletions
|
@ -158,7 +158,7 @@ class _ProactorBasePipeTransport(transports._FlowControlMixin,
|
|||
# end then it may fail with ERROR_NETNAME_DELETED if we
|
||||
# just close our end. First calling shutdown() seems to
|
||||
# cure it, but maybe using DisconnectEx() would be better.
|
||||
if hasattr(self._sock, 'shutdown'):
|
||||
if hasattr(self._sock, 'shutdown') and self._sock.fileno() != -1:
|
||||
self._sock.shutdown(socket.SHUT_RDWR)
|
||||
self._sock.close()
|
||||
self._sock = None
|
||||
|
|
|
@ -237,6 +237,14 @@ class ProactorSocketTransportTests(test_utils.TestCase):
|
|||
test_utils.run_briefly(self.loop)
|
||||
self.assertFalse(self.protocol.connection_lost.called)
|
||||
|
||||
def test_close_invalid_sockobj(self):
|
||||
tr = self.socket_transport()
|
||||
self.sock.fileno.return_value = -1
|
||||
tr.close()
|
||||
test_utils.run_briefly(self.loop)
|
||||
self.protocol.connection_lost.assert_called_with(None)
|
||||
self.assertFalse(self.sock.shutdown.called)
|
||||
|
||||
@mock.patch('asyncio.base_events.logger')
|
||||
def test_fatal_error(self, m_logging):
|
||||
tr = self.socket_transport()
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Fix a crash when closing transports where the underlying socket handle is already invalid on the Proactor event loop.
|
Loading…
Add table
Add a link
Reference in a new issue