I have a `kotlinx.coroutines.sync.Mutex` , instant...
# coroutines
c
I have a
kotlinx.coroutines.sync.Mutex
, instantiated with
Mutex()
, which is always used using
lock.withLock("name of the calling function") { … }
. I'm running the same test on JVM & JS. It runs fine on JVM, but on JS it fails with:
Copy code
IllegalStateException: Mutex is locked by <UNLOCKED> but expected get(Id(id=376066526))
What does this mean? How can I debug the source of this? How can the mutex be locked at any point if I'm only using
withLock
, shouldn't that that care of things? What does
locked by <UNLOCKED>
mean?
y
Looking through the source code, it seems to suggest that the mutex is not locked at the point that you're calling
unlock
on it. If it's possible, can you try the
1.7.0-RC
version and see if it produces an exception as well? The mutex implementation was completely rewritten for that one, so you might have some luck there.
That error message is misleading btw because it only triggers if you have an owner (in this case your function name). If you didn't supply an owner, it gives the much-better error of "Mutex is not locked"
c
How can the mutex not be locked when
unlock
is called, if I never use the mutex any other way than
withLock
?
Same error with 1.7.0-RC, but I get the nicer error message:
Copy code
IllegalStateException: This mutex is not locked
Wait no, there's something wrong on my side.
Just checked, and indeed it still fails with 1.7.0-RC with the "This mutex is not locked" error message
d
If you only use
withLock
, nothing of this sort should happen. Could you file this to https://github.com/Kotlin/kotlinx.coroutines/issues? It would also help a lot if you attached some code where the issue reproduces.
c
Sorry it took me some time to properly reproduce this. Here's the issue: https://github.com/Kotlin/kotlinx.coroutines/issues/3754