From 9b696cf2125729c3f5052b41c83c8e71db0df314 Mon Sep 17 00:00:00 2001 From: Gaurav Pandey Date: Fri, 4 Jun 2021 18:42:37 +0530 Subject: [PATCH] api: Expose event_queue_longpoll_timeout_seconds in /register. Rename poll_timeout to event_queue_longpoll_timeout_seconds and change its value from 90000 ms to 90 sec. Expose its value in register api response when realm data is fetched. Bump API_FEATURE_LEVEL to 74. --- static/js/server_events.js | 2 +- templates/zerver/api/changelog.md | 6 ++++++ version.py | 2 +- zerver/lib/events.py | 3 +++ zerver/lib/home.py | 1 - zerver/openapi/zulip.yaml | 20 ++++++++++++++++++++ zerver/tests/test_home.py | 2 +- zproject/computed_settings.py | 4 ++-- zproject/test_extra_settings.py | 2 +- 9 files changed, 35 insertions(+), 7 deletions(-) diff --git a/static/js/server_events.js b/static/js/server_events.js index 10702654f6..f038a8f16c 100644 --- a/static/js/server_events.js +++ b/static/js/server_events.js @@ -211,7 +211,7 @@ function get_events({dont_block = false} = {}) { url: "/json/events", data: get_events_params, idempotent: true, - timeout: page_params.poll_timeout, + timeout: page_params.event_queue_longpoll_timeout_seconds * 1000, success(data) { watchdog.set_suspect_offline(false); try { diff --git a/templates/zerver/api/changelog.md b/templates/zerver/api/changelog.md index 70b4e15a2f..f669059a8e 100644 --- a/templates/zerver/api/changelog.md +++ b/templates/zerver/api/changelog.md @@ -11,6 +11,12 @@ below features are supported. ## Changes in Zulip 5.0 +**Feature level 74** + +* [`POST /register`](/api/register-queue): Added `server_needs_upgrade` + and `event_queue_longpoll_timeout_seconds` field when fetching + realm data. + **Feature level 73** * [`GET /users`](/api/get-users), [`GET /users/{user_id}`](/api/get-user), diff --git a/version.py b/version.py index 1ba3fb3e43..c4e901766a 100644 --- a/version.py +++ b/version.py @@ -33,7 +33,7 @@ DESKTOP_WARNING_VERSION = "5.4.3" # Changes should be accompanied by documentation explaining what the # new level means in templates/zerver/api/changelog.md, as well as # "**Changes**" entries in the endpoint's documentation in `zulip.yaml`. -API_FEATURE_LEVEL = 73 +API_FEATURE_LEVEL = 74 # Bump the minor PROVISION_VERSION to indicate that folks should provision # only when going from an old version of the code to a newer version. Bump diff --git a/zerver/lib/events.py b/zerver/lib/events.py index 159581d51d..c9cdc740f8 100644 --- a/zerver/lib/events.py +++ b/zerver/lib/events.py @@ -277,6 +277,9 @@ def fetch_initial_state_data( state["giphy_rating_options"] = realm.GIPHY_RATING_OPTIONS state["server_needs_upgrade"] = is_outdated_server(user_profile) + state[ + "event_queue_longpoll_timeout_seconds" + ] = settings.EVENT_QUEUE_LONGPOLL_TIMEOUT_SECONDS # TODO: Should these have the realm prefix replaced with server_? state["realm_push_notifications_enabled"] = push_notifications_enabled() diff --git a/zerver/lib/home.py b/zerver/lib/home.py index 3fe78dca1c..3c49a4709c 100644 --- a/zerver/lib/home.py +++ b/zerver/lib/home.py @@ -183,7 +183,6 @@ def build_page_params_for_home_page_load( page_params = dict( ## Server settings. test_suite=settings.TEST_SUITE, - poll_timeout=settings.POLL_TIMEOUT, insecure_desktop_app=insecure_desktop_app, login_page=settings.HOME_NOT_LOGGED_IN, save_stacktraces=settings.SAVE_FRONTEND_STACKTRACES, diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml index 4ae7e43f1e..1469f0662c 100644 --- a/zerver/openapi/zulip.yaml +++ b/zerver/openapi/zulip.yaml @@ -141,6 +141,13 @@ paths: This endpoint allows you to receive new events from [a registered event queue](/api/register-queue). + + Long-lived clients should use the + `event_queue_longpoll_timeout_seconds` property returned by + `POST /register` as the client-side HTTP request timeout for + calls to this endpoint. It is guaranteed to be higher than + heartbeat frequency and should be respected by clients to + avoid breaking when heartbeat frequency increases. parameters: - $ref: "#/components/parameters/QueueId" - name: last_event_id @@ -8986,6 +8993,19 @@ paths: such that the web app will display to the current user a prominent warning. **Changes**: New in Zulip 5.0 (feature level 74). + event_queue_longpoll_timeout_seconds: + type: integer + description: | + Present if `realm` is present in `fetch_event_types`. + + Recommended client-side HTTP request timeout for [`GET /events`](/api/get-events) calls. + This is guaranteed to be somewhat greater than the heartbeat frequency. It is important + that clients respect this parameter, so that increases in the heartbeat frequency do not + break clients. + + **Changes**: New in Zulip 5.0 (feature level 74). Previously, + this was hardcoded to 90 seconds, and clients should use that as a fallback + value when interacting with servers where this field is not present. realm_notifications_stream_id: type: integer description: | diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.py index 603541d46c..98eb84f29c 100644 --- a/zerver/tests/test_home.py +++ b/zerver/tests/test_home.py @@ -83,6 +83,7 @@ class HomeTest(ZulipTestCase): "enable_stream_email_notifications", "enable_stream_push_notifications", "enter_sends", + "event_queue_longpoll_timeout_seconds", "first_in_realm", "fluid_layout_width", "full_name", @@ -126,7 +127,6 @@ class HomeTest(ZulipTestCase): "password_min_guesses", "password_min_length", "pm_content_in_desktop_notifications", - "poll_timeout", "presence_enabled", "presences", "prompt_for_invites", diff --git a/zproject/computed_settings.py b/zproject/computed_settings.py index aaac7c3406..3e45820c8b 100644 --- a/zproject/computed_settings.py +++ b/zproject/computed_settings.py @@ -988,12 +988,12 @@ else: LOGIN_REDIRECT_URL = "/" -# Client-side polling timeout for get_events, in milliseconds. +# Client-side polling timeout for get_events, in seconds. # We configure this here so that the client test suite can override it. # We already kill the connection server-side with heartbeat events, # but it's good to have a safety. This value should be greater than # (HEARTBEAT_MIN_FREQ_SECS + 10) -POLL_TIMEOUT = 90 * 1000 +EVENT_QUEUE_LONGPOLL_TIMEOUT_SECONDS = 90 ######################################################################## # SSO AND LDAP SETTINGS diff --git a/zproject/test_extra_settings.py b/zproject/test_extra_settings.py index b3559a3405..78002f0a63 100644 --- a/zproject/test_extra_settings.py +++ b/zproject/test_extra_settings.py @@ -63,7 +63,7 @@ if "BAN_CONSOLE_OUTPUT" in os.environ: # Decrease the get_updates timeout to 1 second. # This allows frontend tests to proceed quickly to the next test step. -POLL_TIMEOUT = 1000 +EVENT_QUEUE_LONGPOLL_TIMEOUT_SECONDS = 1 # Stores the messages in `django.core.mail.outbox` rather than sending them. EMAIL_BACKEND = "django.core.mail.backends.locmem.EmailBackend"