From ed86e26706fe0d07bc8849c8dae3e44a72ae0675 Mon Sep 17 00:00:00 2001 From: jrconlin Date: Fri, 7 Apr 2017 09:41:52 -0700 Subject: [PATCH] bug: APNS may close a socket prematurely, resulting in an AttributeError Updates some reqs closes #862 --- autopush/router/apns2.py | 5 ++++- autopush/router/apnsrouter.py | 2 +- requirements.txt | 12 ++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/autopush/router/apns2.py b/autopush/router/apns2.py index 0c6e9dc2..45ba64ec 100644 --- a/autopush/router/apns2.py +++ b/autopush/router/apns2.py @@ -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'] @@ -135,7 +138,7 @@ def send(self, router_token, payload, apns_id, "your message {}".format(reason), log_exception=False ) - except HTTP20Error: + except (HTTP20Error, AttributeError): connection.close() raise finally: diff --git a/autopush/router/apnsrouter.py b/autopush/router/apnsrouter.py index a5800ac1..0b484a52 100644 --- a/autopush/router/apnsrouter.py +++ b/autopush/router/apnsrouter.py @@ -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 diff --git a/requirements.txt b/requirements.txt index 600d605c..21c9200d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,10 +6,10 @@ autobahn[twisted]==0.16.0 boto==2.42.0 boto3==1.4.0 botocore==1.4.50 -cffi==1.7.0 +cffi==1.10.0 click==6.6 contextlib2==0.5.4 -cryptography==1.7.2 +cryptography==1.8.1 cyclone==1.1 datadog==0.13.0 decorator==4.0.10 @@ -17,9 +17,9 @@ enum34==1.1.6 future==0.15.2 futures==3.0.5 gcm-client==0.1.4 -hyper==0.6.2 -idna==2.1 -ipaddress==1.0.16 +hyper==0.7.0 +idna==2.5 +ipaddress==1.0.18 jmespath==0.9.0 marshmallow==2.10.2 marshmallow_polyfield==3.1 @@ -32,7 +32,7 @@ pycrypto==2.6.1 pyfcm==1.0.4 python-dateutil==2.5.3 raven==5.25.0 -requests==2.11.0 +requests==2.13.0 service-identity==16.0.0 simplejson==3.8.2 six==1.10.0