Skip to content
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

[native-mt] ClassCastException when executing iOS tests with coroutines #3254

Closed
marekniedbach-silvair opened this issue Apr 14, 2022 · 2 comments
Labels

Comments

@marekniedbach-silvair
Copy link

Hello,
I'm very sorry about the lack of details, but I have failing the unit tests in one of the internal class related to the kotlin coroutines.

When testing the production code that heavy rely on the coroutines (many launch and delay inside), the unit test is sometimes failing. It is not fully reproducible, as it happens only when executing ./gradlew clean check command. When I run the check command (without the clean) again then everything is passing without an issue. What's more weird, not the same test is failing after clean.

The top of the callstack with the exception looks like below:

kotlin.ClassCastException: kotlinx.coroutines.internal.Removed cannot be cast to kotlinx.coroutines.internal.LockFreeLinkedListNode
	at kotlin.Throwable#<init>(/Users/teamcity3/buildAgent/work/c3a91df21e46e2c8/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Throwable.kt:24)
	at kotlin.Exception#<init>(/Users/teamcity3/buildAgent/work/c3a91df21e46e2c8/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Exceptions.kt:23)
	at kotlin.RuntimeException#<init>(/Users/teamcity3/buildAgent/work/c3a91df21e46e2c8/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Exceptions.kt:34)
	at kotlin.ClassCastException#<init>(/Users/teamcity3/buildAgent/work/c3a91df21e46e2c8/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Exceptions.kt:106)
	at <global>.ThrowClassCastException(/Users/teamcity3/buildAgent/work/c3a91df21e46e2c8/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/RuntimeUtils.kt:31)
	at kotlinx.coroutines.internal#unwrap__at__kotlin.Any(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/concurrent/src/internal/LockFreeLinkedList.kt:668)
	at kotlinx.coroutines.JobSupport.notifyCancelling#internal(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/JobSupport.kt:332)
	at kotlinx.coroutines.JobSupport.tryMakeCancelling#internal(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/JobSupport.kt:810)
	at kotlinx.coroutines.JobSupport.makeCancelling#internal(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/JobSupport.kt:766)
	at kotlinx.coroutines.JobSupport#cancelImpl(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/JobSupport.kt:682)
	at kotlinx.coroutines.JobSupport#cancelCoroutine(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/JobSupport.kt:669)
	at kotlinx.coroutines.TimeoutCoroutine.run#internal(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/Timeout.kt:159)
	at kotlinx.coroutines.test.TestDispatcher#processEvent(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-test/common/src/TestDispatcher.kt:28)
	at kotlinx.coroutines.test.TestCoroutineScheduler.tryRunNextTask#internal(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-test/common/src/TestCoroutineScheduler.kt:95)
	at kotlinx.coroutines.test.TestCoroutineScheduler#advanceUntilIdle(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-test/common/src/TestCoroutineScheduler.kt:110)
	at kotlinx.coroutines.test.$runTestCoroutineCOROUTINE$202#invokeSuspend(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-test/common/src/TestBuilders.kt:212)
	at kotlinx.coroutines.test#runTestCoroutine(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-test/common/src/TestBuilders.kt:198)
	at kotlinx.coroutines.test.$runTest$<anonymous>_3COROUTINE$203.invokeSuspend#internal(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-test/common/src/TestBuilders.kt:167)
	at kotlinx.coroutines.test.$runTest$<anonymous>_3COROUTINE$203.invoke#internal(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-test/common/src/TestBuilders.kt:166)
	at kotlinx.coroutines.test.$createTestResult$lambda-0COROUTINE$208.invokeSuspend#internal(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-test/native/src/TestBuilders.kt:13)
	at kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(/Users/teamcity3/buildAgent/work/c3a91df21e46e2c8/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/coroutines/ContinuationImpl.kt:30)
	at kotlinx.coroutines.DispatchedTask#run(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/internal/DispatchedTask.kt:106)
	at kotlinx.coroutines.EventLoopImplBase#processNextEvent(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/EventLoop.common.kt:281)
	at kotlinx.coroutines#runEventLoop(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Builders.kt:87)
	at kotlinx.coroutines.BlockingCoroutine.joinBlocking#internal(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Builders.kt:74)
	at kotlinx.coroutines#runBlocking(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Builders.kt:55)
	at kotlinx.coroutines#runBlocking$default(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Builders.kt:35)
	at kotlinx.coroutines.test#createTestResult(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-test/native/src/TestBuilders.kt:12)
	at kotlinx.coroutines.test#runTest__at__kotlinx.coroutines.test.TestScope(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-test/common/src/TestBuilders.kt:166)
	at kotlinx.coroutines.test#runTest(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-test/common/src/TestBuilders.kt:154)
	at kotlinx.coroutines.test#runTest$default(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-test/common/src/TestBuilders.kt:147)

I can't provide the example project as it is hard to understand for me what is happening, and the whole project is a bit complicated.

I have the issue above even If I don't use the kotlinx-coroutines-test library at all - I have a custom implementation of time control with the use of internal api too - so it looks like the issue is more in the coroutines library than the coroutines-test.

Versions:
kotlin-gradle-plugin:1.6.20
kotlinx-coroutines-core:1.6.0-native-mt

@qwwdfsad
Copy link
Collaborator

I would suggest migrating to new MM and regular coroutine builds as native-mt is being decommissioned: #462 (comment)

We still ready to fix critical bugs during 1.6.x lifetime, but unfortunately it doesn't seem to be it.

@marekniedbach-silvair
Copy link
Author

I've migrated our project to new MM and it works without the mentioned issue 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants