Skip to content

ReceiveChannel.onReceiveOrClosed throws when selecting on already-closed channel #1584

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
zach-klippenstein opened this issue Oct 1, 2019 · 0 comments
Assignees
Labels

Comments

@zach-klippenstein
Copy link
Contributor

zach-klippenstein commented Oct 1, 2019

When using onReceiveOrClosed (#330) to select on a channel that has already been closed, the select builder fails.

Extremely simple to reproduce:

runBlocking {
  val channel = Channel<Unit>(RENDEZVOUS)
  channel.close()
  select<Unit> {
    channel.onReceiveOrClosed {
      println(it)
    }
  }
}

Exception:

java.lang.AssertionError
	at kotlinx.coroutines.selects.SelectBuilderImpl.resumeWith(Select.kt:444)
	at kotlinx.coroutines.intrinsics.UndispatchedKt.startCoroutineUnintercepted(Undispatched.kt:171)
	at kotlinx.coroutines.channels.AbstractChannel.registerSelectReceiveOrClosed(AbstractChannel.kt:749)
	at kotlinx.coroutines.channels.AbstractChannel.access$registerSelectReceiveOrClosed(AbstractChannel.kt:472)
	at kotlinx.coroutines.channels.AbstractChannel$onReceiveOrClosed$1.registerSelectClause1(AbstractChannel.kt:733)
	at kotlinx.coroutines.selects.SelectBuilderImpl.invoke(Select.kt:415)
	at com.squareup.workflow.Repro$asplode$1.invokeSuspend(Repro.kt:44)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:241)
	at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:270)
	at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:79)
	at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:54)
	at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
	at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:36)
	at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)

Replacing onReceiveOrClosed with onReceiveOrNull works as expected – null is returned from select and the program finishes normally.

Versions:
Kotlin: 1.3.50
Coroutines: 1.3.1

@zach-klippenstein zach-klippenstein changed the title ReceiveChannel.onReceiveOrClose throws when selecting on already-closed channel ReceiveChannel.onReceiveOrClosed throws when selecting on already-closed channel Oct 1, 2019
zach-klippenstein added a commit to square/workflow that referenced this issue Oct 1, 2019
zach-klippenstein added a commit to square/workflow that referenced this issue Oct 1, 2019
zach-klippenstein added a commit to square/workflow that referenced this issue Oct 1, 2019
zach-klippenstein added a commit to square/workflow that referenced this issue Oct 1, 2019
@qwwdfsad qwwdfsad self-assigned this Oct 1, 2019
@qwwdfsad qwwdfsad added the bug label Oct 1, 2019
qwwdfsad added a commit that referenced this issue Oct 8, 2019
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