From d29d132e8ae1261b368447ba1f1367e640a11aa3 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Thu, 7 Dec 2023 12:23:54 -0800 Subject: [PATCH] push_notifications: Set more reasonable timeouts. --- zerver/lib/remote_server.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/zerver/lib/remote_server.py b/zerver/lib/remote_server.py index 9c14fe81d1..7e5cf49c61 100644 --- a/zerver/lib/remote_server.py +++ b/zerver/lib/remote_server.py @@ -20,8 +20,8 @@ from zerver.models import OrgTypeEnum, Realm, RealmAuditLog class PushBouncerSession(OutgoingSession): - def __init__(self) -> None: - super().__init__(role="push_bouncer", timeout=30) + def __init__(self, timeout: int = 15) -> None: + super().__init__(role="push_bouncer", timeout=timeout) class PushNotificationBouncerError(Exception): @@ -98,9 +98,23 @@ def send_to_push_bouncer( headers = {"User-agent": f"ZulipServer/{ZULIP_VERSION}"} headers.update(extra_headers) + if endpoint == "server/analytics": + # Uploading audit log and/or analytics data can require the + # bouncer to do a significant chunk of work in a few + # situations; since this occurs in background jobs, set a long + # timeout. + session = PushBouncerSession(timeout=90) + else: + session = PushBouncerSession() + try: - res = PushBouncerSession().request( - method, url, data=post_data, auth=api_auth, verify=True, headers=headers + res = session.request( + method, + url, + data=post_data, + auth=api_auth, + verify=True, + headers=headers, ) except ( requests.exceptions.Timeout,