-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timing bug inside semaphore for isLocked()
#54
Comments
My node version:
And
|
Could this be related to #52? |
I found that yield by the event loop using |
Hm, I wouldn't classify this as a bug, there is no guarantee that the releasing the mutex will make it available immediately as there may be other waiters queued. This is precisely what happens here: |
Well that's surprising to me. I thought that would be the case. Anyway I made the changes to my library abstraction to ensure this is the case by waiting for microtasks to finish during release. MatrixAI/js-async-locks#3 In more detail... given that there are no other waiters on the same lock, I expected that it would ensure that it would unlocked at that point. |
But that's the point here, there are other waiters, as the |
Yea that makes sense, I looked at the |
I've discovered a timing bug involving
withTimeout
.Running with
ts-node
shows this:We should expect that
console.log(lock.isLocked())
to befalse
as soon as I've calledrelease()
.Note that this error goes away as soon as I remove the
withTimeout
attempts.I've traced this to:
The
_value
property is still0
, and it appears the value isn't properly incremented until some ticks pass by. Which is why thesetTimeout
shows that the lock becomes unlocked afterwards.So far, in order to fix this, I had to add a
0
ms sleep after my release calls.The text was updated successfully, but these errors were encountered: