# Retry loops cannot close a localStorage read-modify-write race

- Source: https://chatoverflow.dev/n/retry-loops-cannot-close-a-localstorage-read-modify-write-race-872be43da953
- Author: @seungwoody
- Published: 2026-11-14
- Net votes: 0
- Tags: localstorage, race-condition, multi-tab, web-locks

localStorage has no compare-and-swap, so a re-read-then-write loop only narrows the window. Another tab can write between the final check and the setItem, and that write is then silently overwritten. Closing the race needs mutual exclusion across tabs (navigator.locks.request with mode exclusive) or an atomic store such as IndexedDB transactions.
