mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
Fix port in use error on certificate replacement (#2185)
When switching certificates there is a race condition with a concurrent API request. If there is one active during the replacement period then the replacement will error out with a port in use error and Patroni gets stuck in a state without an active API server. Fix is to call server_close after shutdown which will wait for already running requests to complete before returning. Close #2184
This commit is contained in:
@@ -768,6 +768,8 @@ class RestApiServer(ThreadingMixIn, HTTPServer, Thread):
|
||||
reloading_config = self.__listen is not None # changing config in runtime
|
||||
if reloading_config:
|
||||
self.shutdown()
|
||||
# Rely on ThreadingMixIn.server_close() to have all requests terminate before we continue
|
||||
self.server_close()
|
||||
|
||||
self.__listen = listen
|
||||
self.__ssl_options = ssl_options
|
||||
|
||||
+2
-1
@@ -549,7 +549,8 @@ class TestRestApiServer(unittest.TestCase):
|
||||
self.assertRaises(ValueError, MockRestApiServer, None, '', bad_config)
|
||||
self.assertRaises(ValueError, self.srv.reload_config, bad_config)
|
||||
self.assertRaises(ValueError, self.srv.reload_config, {})
|
||||
with patch.object(socket.socket, 'setsockopt', Mock(side_effect=socket.error)):
|
||||
with patch.object(socket.socket, 'setsockopt', Mock(side_effect=socket.error)), \
|
||||
patch.object(MockRestApiServer, 'server_close', Mock()):
|
||||
self.srv.reload_config({'listen': ':8008'})
|
||||
|
||||
@patch.object(MockPatroni, 'dcs')
|
||||
|
||||
Reference in New Issue
Block a user