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
Improve error handling for DispatchedTask being in invalid state: #3991
Comments
I didn't mention it, but this happens only on iOS, Kotlin Native. The complete stack trace is here:
|
To add to the above: I see this code in kotlin stdlib, ContinuationImpl.kt:
If releaseIntercepted() would be called more than once for some reason a ClassCastException would occur, because there is a force cast to DispatchedContinuation in the implementation of releaseInterceptedContinuation (CoroutineDispatcher.kt). |
We typically don't allow So, while there might be some workarounds, the only reasonable action here is for us to fix the problem. If you have any pointers regarding its reproducibility, please don't hesitate to share |
We made a fork where we ensure Continuation is always of type DispatchedContinuation on initialization/creation of the class (no forced runtime casts), which seems to work. This way we were able to find the root cause which seems to be a suspending function part of some interface which was implemented on the iOS side. We made this function an ordinary function with a completion handler and the crash went away. See the attached diff for the changes we made in our fork. |
That's a new pattern of usages for us, thanks! |
|
Describe the bug
The primary crash in our Kotlin Multiplatform project is related to the following force cast in
DispatchedTask.kt
:In crashlytics the exception is shown as follows:
Now I understand this crash may be caused by invalid usage of the API, however a class cast exception should never occur. Also it is very hard to debug this way. As of yet, I have no clue if we cause this error ourselves or one of the libraries (e.g. KTOR) causes it.
I propose a solution where at the point the invalid call is made an IllegalStateException or similar exception is thrown, describing the invalid usage of the API, so the code can be fixed at that point.
Provide a Reproducer
I unfortunately don't know how to exactly reproduce this problem. I don't know which call causes this error.
The text was updated successfully, but these errors were encountered: