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

Useless exception when offering to actor with cancelled parent #950

Closed
Pitel opened this issue Jan 22, 2019 · 2 comments
Closed

Useless exception when offering to actor with cancelled parent #950

Pitel opened this issue Jan 22, 2019 · 2 comments
Assignees

Comments

@Pitel
Copy link

Pitel commented Jan 22, 2019

Let's have this very simplified code:

val job = Job()

val actor = actor<Int>(job, Channel.UNLIMITED) {
	consumeEach {
		println(it)
	}
}

job.cancel()
actor.offer(1)

The last line (offer) causes this exception:

kotlinx.coroutines.JobCancellationException: Job was cancelled; job=JobImpl{Cancelled}@8c661fc
	at kotlinx.coroutines.JobSupport.createJobCancellationException(JobSupport.kt:615)
	at kotlinx.coroutines.JobSupport.createCauseException(JobSupport.kt:640)
	at kotlinx.coroutines.JobSupport.cancelMakeCompleting(JobSupport.kt:604)
	at kotlinx.coroutines.JobSupport.cancelImpl(JobSupport.kt:592)
	at kotlinx.coroutines.JobSupport.cancel(JobSupport.kt:575)
	at kotlinx.coroutines.JobSupport.cancel(JobSupport.kt:570)
	at cz.masterapp.annie2.coroutines.JobTest$test$1.invokeSuspend(JobTest.kt:25)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32)
	at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:233)
	at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.kt:116)
	at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:76)
	at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:53)
	at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
	at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:35)
	at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
	at cz.masterapp.annie2.coroutines.JobTest.test(JobTest.kt:16)

One would typically look at JobTest.kt:25, but on line 25 is actualy the cancel() call, making the problematic offer untracable. 😿

In practice, the offers and cancels might be in different files/classes and good luck searching which offer is the cause.

@qwwdfsad
Copy link
Collaborator

We have a debug mode for this (-ea flag or kotlinx.coroutines.stacktrace.recovery=on property).

We can't change general channel contract in old actors, but maybe we can fix it in new actors

@Pitel
Copy link
Author

Pitel commented Jan 23, 2019

From what I see in the code, the kotlinx.coroutines.stacktrace.recovery is enabled by default, if you have kotlinx.coroutines.debug enabled. Which I have, and still gets this useless stack trace.

Maybe I should look att the kotlinx-coroutines-debug module, but it's something completely new for me, and from the readme, it doesn't even say anything about better exception handling.

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

No branches or pull requests

3 participants