From b152fef766fae479e4c676d494fd3955725d0701 Mon Sep 17 00:00:00 2001 From: Blake Gong Date: Mon, 26 Apr 2021 23:30:30 +0800 Subject: [PATCH] Improve retry robustness --- apns2/client.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apns2/client.py b/apns2/client.py index 0947350..94cc89f 100644 --- a/apns2/client.py +++ b/apns2/client.py @@ -253,6 +253,11 @@ def connect(self) -> None: while retries < MAX_CONNECTION_RETRIES: # noinspection PyBroadException try: + if retries > 0: + # HTTP20Connection._sock might get stuck, this line closes the HTTP20Connection manually to reset it + # fully from the second retry onwards + self._connection.close() + self._connection.connect() logger.info('Connected to APNs') return