Skip to content

ChannelAtomicCancelStressTest fails with CoroutinesInternalError caused by ClassCastException #1588

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

Closed
elizarov opened this issue Oct 1, 2019 · 13 comments

Comments

@elizarov
Copy link
Contributor

elizarov commented Oct 1, 2019

https://teamcity.jetbrains.com/viewLog.html?buildId=2565122&buildTypeId=KotlinTools_KotlinxCoroutines_BuildWindows
ChannelAtomicCancelStressTest.testAtomicCancelStress[RendezvousChannel]

kotlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for CancellableContinuation(DispatchedContinuation[ThreadPoolDispatcher[2, ChannelAtomicCancelStressTest], Continuation at kotlinx.coroutines.channels.ChannelAtomicCancelStressTest$launchReceiver$1.invokeSuspend(ChannelAtomicCancelStressTest.kt:135)@7015c908]){CancelledContinuation[kotlinx.coroutines.JobCancellationException: Job was cancelled; job="coroutine#563998":StandaloneCoroutine{Cancelled}@7ed2297a]}@7aeda278. Please read KDoc to 'handleFatalException' method and report this incident to maintainers
	at kotlinx.coroutines.DispatchedTask.handleFatalException$kotlinx_coroutines_core(DispatchedTask.kt:86)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:57)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassCastException: kotlin.coroutines.jvm.internal.CompletedContinuation cannot be cast to kotlinx.coroutines.DispatchedContinuation
	at kotlinx.coroutines.CoroutineDispatcher.releaseInterceptedContinuation(CoroutineDispatcher.kt:106)
	at kotlin.coroutines.jvm.internal.ContinuationImpl.releaseIntercepted(ContinuationImpl.kt:118)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:39)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:192)
	... 7 more
@elizarov
Copy link
Contributor Author

elizarov commented Oct 1, 2019

https://teamcity.jetbrains.com/viewLog.html?buildId=2555599&buildTypeId=KotlinTools_KotlinxCoroutines_BuildWindows
ChannelAtomicCancelStressTest.testAtomicCancelStress[RendezvousChannel]

kotlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for CancellableContinuation(DispatchedContinuation[ThreadPoolDispatcher[2, ChannelAtomicCancelStressTest], Continuation at kotlinx.coroutines.channels.ChannelAtomicCancelStressTest$launchSender$1.invokeSuspend(ChannelAtomicCancelStressTest.kt:108)@54cd1478]){CancelledContinuation[kotlinx.coroutines.JobCancellationException: Job was cancelled; job="coroutine#567226":StandaloneCoroutine{Cancelled}@11cf9085]}@6477608b. Please read KDoc to 'handleFatalException' method and report this incident to maintainers
	at kotlinx.coroutines.DispatchedTask.handleFatalException$kotlinx_coroutines_core(DispatchedTask.kt:86)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:57)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassCastException: kotlin.coroutines.jvm.internal.CompletedContinuation cannot be cast to kotlinx.coroutines.DispatchedContinuation
	at kotlinx.coroutines.CoroutineDispatcher.releaseInterceptedContinuation(CoroutineDispatcher.kt:106)
	at kotlin.coroutines.jvm.internal.ContinuationImpl.releaseIntercepted(ContinuationImpl.kt:118)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:39)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:192)
	... 7 more

@elizarov
Copy link
Contributor Author

elizarov commented Oct 1, 2019

https://teamcity.jetbrains.com/viewLog.html?buildId=2556063&tab=buildResultsDiv&buildTypeId=KotlinTools_KotlinxCoroutines_Build#testNameId-3299188611556527194
ChannelAtomicCancelStressTest.testAtomicCancelStress[RendezvousChannel]

kotlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for CancellableContinuation(DispatchedContinuation[ThreadPoolDispatcher[2, ChannelAtomicCancelStressTest], Continuation at kotlinx.coroutines.channels.ChannelAtomicCancelStressTest$launchSender$1.invokeSuspend(ChannelAtomicCancelStressTest.kt:108)@3ea5b47b]){CancelledContinuation[kotlinx.coroutines.JobCancellationException: Job was cancelled; job="coroutine#897075":StandaloneCoroutine{Cancelled}@7b38ff4b]}@50e96830. Please read KDoc to 'handleFatalException' method and report this incident to maintainers
	at kotlinx.coroutines.DispatchedTask.handleFatalException$kotlinx_coroutines_core(DispatchedTask.kt:92)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:63)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassCastException: kotlin.coroutines.jvm.internal.CompletedContinuation cannot be cast to kotlinx.coroutines.DispatchedContinuation
	at kotlinx.coroutines.CoroutineDispatcher.releaseInterceptedContinuation(CoroutineDispatcher.kt:106)
	at kotlin.coroutines.jvm.internal.ContinuationImpl.releaseIntercepted(ContinuationImpl.kt:118)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:39)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:187)
	... 7 more

@elizarov elizarov changed the title ChannelAtomicCancelStressTest fails with ClassCastException ChannelAtomicCancelStressTest fails with AssertionError Oct 1, 2019
@elizarov elizarov changed the title ChannelAtomicCancelStressTest fails with AssertionError ChannelAtomicCancelStressTest fails with AssertionError caused by ClassCastException Oct 1, 2019
@elizarov
Copy link
Contributor Author

elizarov commented Oct 1, 2019

https://teamcity.jetbrains.com/viewLog.html?buildId=2565287&tab=buildResultsDiv&buildTypeId=KotlinTools_KotlinxCoroutines_BuildWindows
ChannelAtomicCancelStressTest.testAtomicCancelStress[RendezvousChannel]

kotlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for CancellableContinuation(DispatchedContinuation[ThreadPoolDispatcher[2, ChannelAtomicCancelStressTest], Continuation at kotlinx.coroutines.channels.ChannelAtomicCancelStressTest$launchSender$1.invokeSuspend(ChannelAtomicCancelStressTest.kt:108)@1b1b1a34]){CancelledContinuation[kotlinx.coroutines.JobCancellationException: Job was cancelled; job="coroutine#563669":StandaloneCoroutine{Cancelled}@1e724a8a]}@475be4b. Please read KDoc to 'handleFatalException' method and report this incident to maintainers
	at kotlinx.coroutines.DispatchedTask.handleFatalException$kotlinx_coroutines_core(DispatchedTask.kt:86)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:57)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassCastException: kotlin.coroutines.jvm.internal.CompletedContinuation cannot be cast to kotlinx.coroutines.DispatchedContinuation
	at kotlinx.coroutines.CoroutineDispatcher.releaseInterceptedContinuation(CoroutineDispatcher.kt:106)
	at kotlin.coroutines.jvm.internal.ContinuationImpl.releaseIntercepted(ContinuationImpl.kt:118)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:39)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:192)
	... 7 more

@elizarov elizarov changed the title ChannelAtomicCancelStressTest fails with AssertionError caused by ClassCastException ChannelAtomicCancelStressTest fails with CoroutinesInternalError caused by ClassCastException Oct 1, 2019
elizarov added a commit that referenced this issue Oct 1, 2019
@elizarov
Copy link
Contributor Author

elizarov commented Oct 2, 2019

https://teamcity.jetbrains.com/viewLog.html?buildId=2566584&tab=buildResultsDiv&buildTypeId=KotlinTools_KotlinxCoroutines_Build#testNameId-3299188611556527194
ChannelAtomicCancelStressTest.testAtomicCancelStress[RendezvousChannel]

kotlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for CancellableContinuation(DispatchedContinuation[ThreadPoolDispatcher[2, ChannelAtomicCancelStressTest], Continuation at kotlinx.coroutines.channels.ChannelAtomicCancelStressTest$launchSender$1.invokeSuspend(ChannelAtomicCancelStressTest.kt:108)@7920dc2b]){CancelledContinuation[kotlinx.coroutines.JobCancellationException: Job was cancelled; job="coroutine#1525850":StandaloneCoroutine{Cancelled}@3c225d6b]}@a7657db. Please read KDoc to 'handleFatalException' method and report this incident to maintainers
	at kotlinx.coroutines.DispatchedTask.handleFatalException$kotlinx_coroutines_core(DispatchedTask.kt:86)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:57)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassCastException: kotlin.coroutines.jvm.internal.CompletedContinuation cannot be cast to kotlinx.coroutines.DispatchedContinuation
	at kotlinx.coroutines.CoroutineDispatcher.releaseInterceptedContinuation(CoroutineDispatcher.kt:106)
	at kotlin.coroutines.jvm.internal.ContinuationImpl.releaseIntercepted(ContinuationImpl.kt:118)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:39)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:192)
	... 7 more

@elizarov
Copy link
Contributor Author

elizarov commented Oct 2, 2019

https://teamcity.jetbrains.com/viewLog.html?buildId=2567101&tab=buildResultsDiv&buildTypeId=KotlinTools_KotlinxCoroutines_NightlyStress#testNameId-3299188611556527194
ChannelAtomicCancelStressTest.testAtomicCancelStress[RendezvousChannel]

otlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for CancellableContinuation(DispatchedContinuation[ThreadPoolDispatcher[2, ChannelAtomicCancelStressTest], Continuation at kotlinx.coroutines.channels.ChannelAtomicCancelStressTest$launchReceiver$1.invokeSuspend(ChannelAtomicCancelStressTest.kt:135)@73114b46]){CancelledContinuation[kotlinx.coroutines.JobCancellationException: Job was cancelled; job="coroutine#21157923":StandaloneCoroutine{Cancelled}@64e06ece]}@52a44403. Please read KDoc to 'handleFatalException' method and report this incident to maintainers
	at kotlinx.coroutines.DispatchedTask.handleFatalException$kotlinx_coroutines_core(DispatchedTask.kt:86)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:57)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassCastException: kotlin.coroutines.jvm.internal.CompletedContinuation cannot be cast to kotlinx.coroutines.DispatchedContinuation
	at kotlinx.coroutines.CoroutineDispatcher.releaseInterceptedContinuation(CoroutineDispatcher.kt:106)
	at kotlin.coroutines.jvm.internal.ContinuationImpl.releaseIntercepted(ContinuationImpl.kt:118)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:39)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:192)
	... 7 more

elizarov added a commit that referenced this issue Oct 2, 2019
This bug was introduced by PR #1524. It was reproducing when there
is a regular "send" operation on one side of a channel and
"select { onReceive }" on another side of the channel and the
"send" coroutine gets cancelled. The problem is that
SendElement.tryResumeSend implementation was calling finishPrepare
before it has successfully resumed continuation, so if that
continuation was already cancelled, the code in "finishPrepare" had
already stored the wrong affected node which it would later try to
call "completeResume" on.

This patch also adds hexAddress to the debug toString method of
all internal node classes in channel implementation.

Fixes #1588
elizarov added a commit that referenced this issue Oct 2, 2019
This bug was introduced by PR #1524. It was reproducing when there
is a regular "send" operation on one side of a channel and
"select { onReceive }" on another side of the channel and the
"send" coroutine gets cancelled. The problem is that
SendElement.tryResumeSend implementation was calling finishPrepare
before it has successfully resumed continuation, so if that
continuation was already cancelled, the code in "finishPrepare" had
already stored the wrong affected node which it would later try to
call "completeResume" on.

This patch also adds hexAddress to the debug toString method of
all internal node classes in channel implementation.

Fixes #1588
elizarov added a commit that referenced this issue Oct 3, 2019
This bug was introduced by PR #1524. It was reproducing when there
is a regular "send" operation on one side of a channel and
"select { onReceive }" on another side of the channel and the
"send" coroutine gets cancelled. The problem is that
SendElement.tryResumeSend implementation was calling finishPrepare
before it has successfully resumed continuation, so if that
continuation was already cancelled, the code in "finishPrepare" had
already stored the wrong affected node which it would later try to
call "completeResume" on.

This patch also adds hexAddress to the debug toString method of
all internal node classes in channel implementation.

Fixes #1588
@qwwdfsad
Copy link
Collaborator

qwwdfsad commented Oct 8, 2019

Fixed in develop, was reproducible only in develop

@qwwdfsad qwwdfsad closed this as completed Oct 8, 2019
@debaj
Copy link

debaj commented Mar 10, 2020

The above crash log is reproducible in kotlinx.coroutines version 1.3.3 and 1.3.4

@elizarov
Copy link
Contributor Author

@debaj Can you elaborate? What environment was the code running in?

@anna-berezovskaya
Copy link

@elizarov It happens when the code, running inside coroutine, finishes. The coroutine was called from Java class like that:
BuildersKt.<Boolean>async(CoroutineScopeKt.CoroutineScope(coroutineContextProvider.defaultDispatcher()), coroutineContextProvider.defaultDispatcher(), CoroutineStart.DEFAULT, (coroutineScope, continuation) -> { suspendFunctionCall() } return Unit.INSTANCE; });

@namig-tahmazli
Copy link

@elizarov I am able to reproduce this on coroutines version 1.3.5.

fun main() {
    runBlocking {
        val f = flow<Int> {
            repeat(10){
                println("Emmiting $it")
                emit(it)
            }
        }

        launch {
            f.collect {
                delay(4000)
                println(it)
            }
        }
    }
}

Running the above code gives same excepton.
As far as I know, when the collector is busy the emit should be suspended however the above code snippet prints all without delay by throwing this exception on version 1.3.5.

@elizarov
Copy link
Contributor Author

How reliably it reproduces on your machine? Can you give more details on your setup, please: OS, CPU, Kotlin version, JDK version?

@namig-tahmazli
Copy link

namig-tahmazli commented Jun 17, 2020

Hi @elizarov
Thank you for your reply.

I think I get this error because I am using
Intellij Idea 2018.2.8 with Kotlin plugin 1.3.20 with kotlin 1.3.20 with coroutines 1.3.5.

I just tried on Idea 2019 with Kotin version 1.3.61 with coroutines 1.3.5 and it worked as expected.

@elizarov
Copy link
Contributor Author

elizarov commented Jul 2, 2020

Recent versions of coroutines are not compatible with older versions of Kotlin.

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

No branches or pull requests

5 participants