Close HTTPServer when bind and activate fails

This commit is contained in:
Unrud 2017-08-24 14:34:29 +02:00
parent 31564c7cf2
commit 4cfe92cf50

View File

@ -109,10 +109,6 @@ class HTTPServer(wsgiref.simple_server.WSGIServer):
# Only allow IPv6 connections to the IPv6 socket
self.socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1)
if bind_and_activate:
self.server_bind()
self.server_activate()
if self.max_connections:
self.connections_guard = threading.BoundedSemaphore(
self.max_connections)
@ -120,6 +116,14 @@ class HTTPServer(wsgiref.simple_server.WSGIServer):
# use dummy context manager
self.connections_guard = contextlib.ExitStack()
if bind_and_activate:
try:
self.server_bind()
self.server_activate()
except:
self.server_close()
raise
def get_request(self):
# Set timeout for client
_socket, address = super().get_request()