Skip to content

Commit

Permalink
tornado: Fix race condition on handler._request.
Browse files Browse the repository at this point in the history
Commit 6fd1a55 (zulip#21469) introduced an
await point where get_events_backend calls fetch_events in order to
switch threads.  This opened the possibility that, in the window
between the connect_handler call in fetch_events and the old location
of this assignment in get_events_backend, an event could arrive,
causing ClientDescriptor.add_event to crash on missing
handler._request.  Fix this by assigning handler._request earlier.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
  • Loading branch information
andersk committed Jun 8, 2022
1 parent acfa551 commit 135f1f4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion zerver/tornado/views.py
Expand Up @@ -125,6 +125,7 @@ def get_events_backend(
assert tornado_handler is not None
handler = tornado_handler()
assert handler is not None
handler._request = request

if user_client is None:
valid_user_client = RequestNotes.get_notes(request).client
Expand Down Expand Up @@ -173,7 +174,6 @@ def get_events_backend(
# Return an AsynchronousResponse; this will result in
# Tornado discarding the response and instead long-polling the
# request. See zulip_finish for more design details.
handler._request = request
return AsynchronousResponse()
if result["type"] == "error":
raise result["exception"]
Expand Down

0 comments on commit 135f1f4

Please sign in to comment.