mirror of https://github.com/python/cpython
Issue #22435: Fix a file descriptor leak when SocketServer bind fails.
This commit is contained in:
parent
efc7258377
commit
0f4f048fa5
|
@ -426,8 +426,12 @@ class TCPServer(BaseServer):
|
||||||
self.socket = socket.socket(self.address_family,
|
self.socket = socket.socket(self.address_family,
|
||||||
self.socket_type)
|
self.socket_type)
|
||||||
if bind_and_activate:
|
if bind_and_activate:
|
||||||
self.server_bind()
|
try:
|
||||||
self.server_activate()
|
self.server_bind()
|
||||||
|
self.server_activate()
|
||||||
|
except:
|
||||||
|
self.server_close()
|
||||||
|
raise
|
||||||
|
|
||||||
def server_bind(self):
|
def server_bind(self):
|
||||||
"""Called by constructor to bind the socket.
|
"""Called by constructor to bind the socket.
|
||||||
|
|
|
@ -302,6 +302,16 @@ class SocketServerTest(unittest.TestCase):
|
||||||
t.join()
|
t.join()
|
||||||
s.server_close()
|
s.server_close()
|
||||||
|
|
||||||
|
def test_tcpserver_bind_leak(self):
|
||||||
|
# Issue #22435: the server socket wouldn't be closed if bind()/listen()
|
||||||
|
# failed.
|
||||||
|
# Create many servers for which bind() will fail, to see if this result
|
||||||
|
# in FD exhaustion.
|
||||||
|
for i in range(1024):
|
||||||
|
with self.assertRaises(OverflowError):
|
||||||
|
socketserver.TCPServer((HOST, -1),
|
||||||
|
socketserver.StreamRequestHandler)
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
if imp.lock_held():
|
if imp.lock_held():
|
||||||
|
|
|
@ -27,6 +27,8 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #22435: Fix a file descriptor leak when SocketServer bind fails.
|
||||||
|
|
||||||
- Issue #13096: Fixed segfault in CTypes POINTER handling of large
|
- Issue #13096: Fixed segfault in CTypes POINTER handling of large
|
||||||
values.
|
values.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue