Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

api: Expose event_queue_longpoll_timeout_seconds in /register.

Gaurav Pandey9b696cf21257
diff --git a/static/js/server_events.js b/static/js/server_events.js
index 10702654f66..f038a8f16c7 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 70b4e15a2fb..f669059a8eb 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 1ba3fb3e430..c4e901766aa 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 159581d51de..c9cdc740f82 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 3fe78dca1cc..3c49a4709ca 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 4ae7e43f1e9..1469f0662c8 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 603541d46c0..98eb84f29c9 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 aaac7c3406f..3e45820c8b2 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 b3559a3405f..78002f0a63f 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"