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

Commit

Permalink
Merge pull request #1286 from mozilla-services/fix/1285
Browse files Browse the repository at this point in the history
fix: timeout gcm calls
  • Loading branch information
bbangert authored Aug 21, 2018
2 parents 61a0d38 + 440a9d8 commit d38983c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions autopush/router/gcm.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""GCM Router"""
from typing import Any # noqa

from requests.exceptions import ConnectionError
from requests.exceptions import ConnectionError, Timeout
from twisted.internet.threads import deferToThread
from twisted.logger import Logger

Expand All @@ -27,6 +27,7 @@ def __init__(self, conf, router_conf, metrics):
self.min_ttl = router_conf.get("ttl", 60)
self.dryRun = router_conf.get("dryrun", False)
self.collapseKey = router_conf.get("collapseKey")
timeout = router_conf.get("timeout", 10)
self.gcm = {}
self.senderIDs = {}
# Flatten the SenderID list from human readable and init gcmclient
Expand All @@ -35,7 +36,7 @@ def __init__(self, conf, router_conf, metrics):
for sid in router_conf.get("senderIDs"):
auth = router_conf.get("senderIDs").get(sid).get("auth")
self.senderIDs[sid] = auth
self.gcm[sid] = gcmclient.GCM(auth)
self.gcm[sid] = gcmclient.GCM(auth, timeout=timeout)
self._base_tags = ["platform:gcm"]
self.log.debug("Starting GCM router...")

Expand Down Expand Up @@ -131,6 +132,15 @@ def _route(self, notification, uaid_data):
raise RouterException("Server error", status_code=502,
errno=902,
log_exception=False)
except Timeout as e:
self.log.warn("GCM Timeout: %s" % e)
self.metrics.increment("notification.bridge.error",
tags=make_tags(
self._base_tags,
reason="timeout"))
raise RouterException("Server error", status_code=502,
errno=902,
log_exception=False)
except Exception as e:
self.log.error("Unhandled exception in GCM Routing: %s" % e)
raise RouterException("Server error", status_code=500)
Expand Down

0 comments on commit d38983c

Please sign in to comment.