Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
bug: APNS may close a socket prematurely, resulting in an AttributeError
Browse files Browse the repository at this point in the history
closes #862
  • Loading branch information
jrconlin committed Apr 7, 2017
1 parent 1f3c3b2 commit dd8d1a3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion autopush/router/apns2.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ def send(self, router_token, payload, apns_id,
# re-established.
stream_id = connection.request(
'POST', url=url, body=body, headers=headers)
# get_response() may return an AttributeError. Not really sure
# how it happens, but the connected socket may get set to None.
# We'll treat that as a premature socket closure.
response = connection.get_response(stream_id)
if response.status != 200:
reason = json.loads(response.read().decode('utf-8'))['reason']
Expand All @@ -135,7 +138,7 @@ def send(self, router_token, payload, apns_id,
"your message {}".format(reason),
log_exception=False
)
except HTTP20Error:
except (HTTP20Error, AttributeError) as ex:
connection.close()
raise
finally:
Expand Down
2 changes: 1 addition & 1 deletion autopush/router/apnsrouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def _route(self, notification, router_data):
try:
apns_client.send(router_token=router_token, payload=payload,
apns_id=apns_id)
except ConnectionError as ex:
except (ConnectionError, AttributeError) as ex:
self.ap_settings.metrics.increment(
"updates.client.bridge.apns.connection_err",
self._base_tags
Expand Down

0 comments on commit dd8d1a3

Please sign in to comment.