Kotlinx.coroutines: Ktor js test failed due to `'Fatal exception in coroutines machinery`

Created on 31 Mar 2020  路  4Comments  路  Source: Kotlin/kotlinx.coroutines

Failed to create a minimal reproducer.

oroutinesInternalError{message_q7r8iu$_0: 'Fatal exception in coroutines machinery for DispatchedContinuation[WindowDispatcher@1, [object Object]]. Please read KDoc to 'handleFatalException' method and report this incident to maintainers', cause_us9j0c$_0: ClassCastException{message_8yp7un$_0: 'Illegal cast', cause_th0jdv$_0: null, name: 'ClassCastException'}, name: 'CoroutinesInternalError'
IllegalStateException: Expected class CancellationException exception, but IllegalStateException: Expected class CancellationException exception, but it wasn't thrown was thrown instead
IllegalStateException: Expected class CancellationException exception, but IllegalStateException: Expected class CancellationException exception, but it wasn't thrown was thrown instead
    at IllegalStateException.init(/home/leonid/work/ktor/build/js/packages_imported/kotlin/1.3.71/kotlin/exceptions.kt:66)
    at lambda.doResume(/home/leonid/work/ktor/build/js/packages/ktor-ktor-client-tests/kotlin/util/Preconditions.kt:143)
    at TestClientBuilder.test(/home/leonid/work/ktor/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/WebSocketTest.kt:59)
    at lambda.doResume(/home/leonid/work/ktor/ktor-client/ktor-client-tests/common/src/io/ktor/client/tests/utils/CommonClientTestUtils.kt:59)
    at lambda.CoroutineImpl.resumeWith(/home/leonid/work/ktor/build/js/packages_imported/kotlin/1.3.71/kotlin/coroutines/CoroutineImpl.kt:47)
    at DispatchedContinuation.DispatchedTask.run(/home/leonid/work/ktor/build/js/packages_imported/kotlinx-coroutines-core/1.3.4/kotlinx-coroutines-core.js:32615)
    at WindowMessageQueue.MessageQueue.process(/home/leonid/work/ktor/build/js/packages_imported/kotlinx-coroutines-core/1.3.4/kotlinx-coroutines-core.js:35929)
    at <global>.<unknown>(/home/leonid/work/ktor/build/js/packages_imported/kotlinx-coroutines-core/1.3.4/kotlinx-coroutines-core.js:358847)

To reproduce, run https://github.com/ktorio/ktor/blob/a32553901c32118612aefb998e9569637a3104c5/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/WebSocketTest.kt#L51 after removing "Js" constant.
It fails for both nodejs and browser. The test can be run on the master branch with IDEA.

js

All 4 comments

Hi @e5l , I've stumbled upon a similar issue and found a workaround.

I still haven't figured out why, but for some reason using assertFailsWith(MyException::class) instead of the inline version assertFailsWith<MyException> solved the problem in my project.

Funny enough, the library I'm testing is a websocket library too! Is this a coincidence?

I can't wrap my head around this, and can't create a minimal reproducible example either.
However, among the tests in my project that use an assertFailsWith, most of them consistently fail on JS platforms (both node and browser) when using the inline assertFailsWith<...> overload.

We encountered the same issue with assertFailsWith in our JS tests. Unfortunately, I cannot find the relevant KT ticket, but it appears to be fixed in JS IR

@qwwdfsad Do you know if there's any chance this will be fixed in LEGACY JS compiler as well?
I'm relying on kotlinx-io in my library and it has not been released in a while, no IR version (nor Kotlin 1.4-based version for that matter).

It's better to ask our JS folks (e.g. in JS Slack channel) with a reproducer in your hands.
But it's unlikely to be fixed in legacy BE, I suspect

Was this page helpful?
0 / 5 - 0 ratings