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
CompletionHandlerException caused by IllegalStateException: Mutex is not locked #2683
Comments
It does look like you were affected by a breaking change in 1.4.3: #1937. In particular, the change affects mutexes: before, Thus, if it was observed that CC @elizarov. |
It would not. Code should only call Looking at the code, it does look suspicious: if |
Thanks for pointing out to the problem. It looks like it's possible but since the stacktrace doesn't contain any ktor routines, there is a chance that the particular issue is not caused by ktor itself. Opened KTOR-2646 |
Thanks, guys. For now, I'll disable Ktor Logging and hope that prevents the crashes. I wonder if the exception could be improved to better explain what might have caused it. It is odd that the stacktrace doesn't point to my code or any library I'm using. |
The most important part of the stacktrace is:
Looking at this part I clearly see that the attempt to unlock is made from a lock continuation. So there is a suspended lock invocation that is cancelled, and its cancellation causes unlock while the lock is not yet done. So in spite of that, there is a similar bug in ktor, this particular stack trace proves that there is also a bug in the mutex implementation. This is why I am reopening this. |
@cy6erGn0m I don't think it's a bug in the mutex. Consider the following valid interleaving that could lead to this:
There is a race between steps 4 and 5, and if 4 happens earlier than 5, then 5 will throw with the stacktrace that we observe here. I don't know what happens if 5 happens earlier than 4: then 4 must throw, but we don't observe it, so maybe the exception is getting eaten somewhere. |
What i am saying is that there are two bugs in both ktor and mutex. |
Why do you think there's a bug in the mutex? |
After an internal discussion, we concluded that this stacktrace could be caused purely by the bug in Ktor, and also that it doesn't look like there is an obvious bug in the mutex. |
I'm getting reports of a
CompletionHandlerException
usingCoroutines 1.4.3
andCoroutines 1.5.0-RC
. I have no reports of this withCoroutines 1.4.2
. I don't know whether that's just a coincidence or not. The exception occurs fairly rarely.The text was updated successfully, but these errors were encountered: