Web Locks API solves silent multi-tab logout bug caused by token refresh race
When multiple browser tabs run the same web app simultaneously, they can each independently attempt to refresh an expiring access token at nearly the same millisecond. Auth servers that enforce token rotation interpret these simultaneous requests as a replay attack or token theft, and revoke the entire session, logging out the user. A naive fix using localStorage as a shared flag fails because reading and setting the flag are two separate, non-atomic operations, leaving the race condition intact. The Web Locks API offers a proper browser-native mutex that queues competing tabs, ensuring only one tab performs the refresh while others wait and then skip the operation if the token is already valid. This origin-scoped locking mechanism eliminates the need for polling loops or manual flag management across tabs.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in