You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
eventActions.js: Clarify loop-break logic and fix race condition in startEventPolling.
This follows a discussion at and around
https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/Event.20polling.20optimization.3F/near/810784.
The `queueId !== getState().session.eventQueueId` is not the most
direct way to check that the same user has remained logged in. So,
replace that check and the `auth` check above it with a call to the
new helper function authEquivalent, to check the maybe-stale auth
against the current auth.
Also, the `queueId !== ...` check allows a race condition! We change
`session.eventQueueId` at `REALM_INIT`, which only happens after a
`/register` request *completes*. So a user could switch accounts,
triggering a new `/register` request, but the old account's event
poll could return before that new `/register` completes, and the
`queueId !== ...` will pass, triggering a state update with the old
account's events instead of the new account's. Checking auth
information is what we want here.
It's true that this auth check will not catch the case that a queue
was killed following a period of inactivity (i.e., the
BAD_EVENT_QUEUE_ID). However, this is not a flaw, because the loop
already handles that case correctly without the `queueId !== ...`
check. In particular, if a queue is killed, api.pollForEvents will
reject, and that rejection is handled in the catch block.
When modifying startEventPolling to accept an auth parameter, I
noticed (and added a comment to explain) that some actions being
dispatched in doInitialFetch will throw unhandled errors if a user
logs out while the /register request is in progress. This will be of
concern when we work on #3706.
0 commit comments