From 2237e0e173c9531dd81ac46e0a8c264625ea9fa9 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 10 May 2023 11:12:29 -0400 Subject: [PATCH] Add a retry mechanism for connecting socket Timing is sensitive during the handshake, catch and retry if it should fail. --- .../common/initramfs/opt/confluent/bin/apiclient | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/confluent_osdeploy/common/initramfs/opt/confluent/bin/apiclient b/confluent_osdeploy/common/initramfs/opt/confluent/bin/apiclient index 7f6aea95..12510cc9 100644 --- a/confluent_osdeploy/common/initramfs/opt/confluent/bin/apiclient +++ b/confluent_osdeploy/common/initramfs/opt/confluent/bin/apiclient @@ -353,7 +353,7 @@ class HTTPSClient(client.HTTPConnection, object): raise Exception('Unable to reach any hosts') return foundsrv - def connect(self): + def connect(self, tries=3): addrinf = socket.getaddrinfo(self.host, self.port)[0] psock = socket.socket(addrinf[0]) psock.settimeout(15) @@ -376,6 +376,10 @@ class HTTPSClient(client.HTTPConnection, object): self.errout.write(errmsg) self.errout.flush() sys.exit(1) + except socket.timeout: + if not tries: + raise + return self.connect(tries=tries-1) def grab_url(self, url, data=None, returnrsp=False): return self.grab_url_with_status(url, data, returnrsp)[1]