Fix annoying exceptions on ssl socket shutdown (#2468)

The HAProxy is closing connections as soon as it got the HTTP Status code leaving no time for Patroni to properly shutdown SSL connection.

Close https://github.com/zalando/patroni/issues/2466
This commit is contained in:
Alexander Kukushkin
2022-12-06 11:57:12 +01:00
committed by GitHub
parent b47c50a788
commit 26244634ce
2 changed files with 9 additions and 3 deletions
+4 -1
View File
@@ -845,7 +845,10 @@ class RestApiServer(ThreadingMixIn, HTTPServer, Thread):
def shutdown_request(self, request):
if hasattr(request, 'context'): # SSLSocket
request.unwrap()
try:
request.unwrap()
except Exception as e:
logger.debug('Failed to shutdown SSL connection: %r', e)
super(RestApiServer, self).shutdown_request(request)
def get_certificate_serial_number(self):
+5 -2
View File
@@ -601,8 +601,11 @@ class TestRestApiServer(unittest.TestCase):
self.srv.process_request_thread(Mock(), '2')
@patch.object(MockRestApiServer, 'process_request', Mock(side_effect=RuntimeError))
@patch.object(MockRestApiServer, 'get_request', Mock(return_value=(Mock(), ('127.0.0.1', 55555))))
def test_process_request_error(self):
@patch.object(MockRestApiServer, 'get_request')
def test_process_request_error(self, mock_get_request):
mock_request = Mock()
mock_request.unwrap.side_effect = Exception
mock_get_request.return_value = (mock_request, ('127.0.0.1', 55555))
self.srv._handle_request_noblock()
@patch('ssl._ssl._test_decode_cert', Mock())