fast-mutex
fast-mutex copied to clipboard
Bug? Or does chrome now do weird things?
I'm trying to use this to build a web-locks polyfill. However, I'm seeing that two different browser tabs can acquire a lock at the same time. It appears they will both:
- Set
X
- See
Y
is null - Set
Y
as themselves - And read
X
as themselves.
Obviously, that last set shouldn't be possible.
Any idea what's going on? I'm seeing this in chrome. Thanks!
Putting another setTimeout
here:
setTimeout(()=>{
// if x was changed, another client is contending for an inner lock
let lsX = this.getItem(x);
if (lsX !== this.clientId) {
seems to fix things. It seems to let chrome actually see the other tab's write.
Hello!
After playing with FastMutex for a while, I wasn't able to get it to work. I took some ideas from it and did a rewrite where that uses "only one setTimeout
" at a time.
This seems to have made it work.
You can see the result here: https://github.com/bitovi/web-locks-polyfill.
I added a reference in the main function.
Thanks for building fast-mutex. It saved me at least 2 days of work.
any updates on this issue? @chieffancypants
I'm trying to use this to build a web-locks polyfill. However, I'm seeing that two different browser tabs can acquire a lock at the same time. It appears they will both:
- Set
X
- See
Y
is null- Set
Y
as themselves- And read
X
as themselves.Obviously, that last set shouldn't be possible.
Any idea what's going on? I'm seeing this in chrome. Thanks!
Are these two tabs opened at the same time? @justinbmeyer
Putting another
setTimeout
here:setTimeout(()=>{ // if x was changed, another client is contending for an inner lock let lsX = this.getItem(x); if (lsX !== this.clientId) {
seems to fix things. It seems to let chrome actually see the other tab's write.
is this because that localStorage needs time to sync data?