Commit 03c55402 authored by Jérome Perrin's avatar Jérome Perrin

software/caddy-frontend/test: fix ResourceWarning with unclosed server socket

see commit e6deadaca7f4469ab32e028cdbb029acc9c7d3c3 from slapos.core:

We fork a subprocess to serve requests, but the listening socket is bound
in server constructor and inherited by subprocess. With this pattern, we
have to explicitly close the socket from parent process to prevent the
leak.
parent c6c948e1
......@@ -743,12 +743,15 @@ class HttpFrontendTestCase(SlapOSInstanceTestCase):
server_process = multiprocessing.Process(
target=server.serve_forever, name='HTTPServer')
server_process.start()
# from now on, socket is used by server subprocess, we can close it
server.socket.close()
cls.logger.debug('Started process %s' % (server_process,))
cls.backend_https_url = 'https://%s:%s/' % server_https.server_address
server_https_process = multiprocessing.Process(
target=server_https.serve_forever, name='HTTPSServer')
server_https_process.start()
server_https.socket.close()
cls.logger.debug('Started process %s' % (server_https_process,))
class NetlocHandler(TestHandler):
......@@ -760,6 +763,7 @@ class HttpFrontendTestCase(SlapOSInstanceTestCase):
netloc_a_http_process = multiprocessing.Process(
target=netloc_a_http.serve_forever, name='netloc-a-http')
netloc_a_http_process.start()
netloc_a_http.socket.close()
netloc_b_http = ThreadedHTTPServer(
(cls._ipv4_address, cls._server_netloc_b_http_port),
......@@ -767,6 +771,7 @@ class HttpFrontendTestCase(SlapOSInstanceTestCase):
netloc_b_http_process = multiprocessing.Process(
target=netloc_b_http.serve_forever, name='netloc-b-http')
netloc_b_http_process.start()
netloc_b_http.socket.close()
cls.server_process_list = [
server_process,
......@@ -822,6 +827,7 @@ class HttpFrontendTestCase(SlapOSInstanceTestCase):
self.server_https_auth_process = multiprocessing.Process(
target=server_https_auth.serve_forever, name='HTTPSServerAuth')
self.server_https_auth_process.start()
server_https_auth.socket.close()
self.logger.debug('Started process %s' % (self.server_https_auth_process,))
def stopAuthenticatedServerProcess(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment