Do not inherit rest api port on fork

This commit is contained in:
Alexander Kukushkin
2015-08-26 15:14:44 +02:00
parent 420176aa75
commit 353fc58bee
2 changed files with 8 additions and 0 deletions
+7
View File
@@ -1,3 +1,4 @@
import fcntl
import json
import logging
import psycopg2
@@ -55,6 +56,7 @@ class RestApiServer(ThreadingMixIn, HTTPServer, Thread):
host, port = config['listen'].split(':')
HTTPServer.__init__(self, (host, int(port)), RestApiHandler)
Thread.__init__(self, target=self.serve_forever)
self._set_fd_cloexec(self.socket)
self.patroni = patroni
self.daemon = True
@@ -64,3 +66,8 @@ class RestApiServer(ThreadingMixIn, HTTPServer, Thread):
ret = [r for r in cursor]
cursor.close()
return ret
@staticmethod
def _set_fd_cloexec(fd):
flags = fcntl.fcntl(fd, fcntl.F_GETFD)
fcntl.fcntl(fd, fcntl.F_SETFD, flags | fcntl.FD_CLOEXEC)
+1
View File
@@ -57,6 +57,7 @@ class TestPatroni(unittest.TestCase):
BaseHTTPServer.HTTPServer.__init__ = nop
RestApiServer._BaseServer__is_shut_down = Mock_BaseServer__is_shut_down()
RestApiServer._BaseServer__shutdown_request = True
RestApiServer.socket = 0
with open('postgres0.yml', 'r') as f:
config = yaml.load(f)
with patch.object(Client, 'machines') as mock_machines: