ConflatedBroadcastChannel hangs in offer()
See original GitHub issueHi there,
maybe there is a better way to achieve what I want, but with my current wrapper class around MutableMaps that allows coroutine waiting for key additions will at times get stuck and cause 100% cpu load. I’m using the recently added ConflatedBroadcastChannel class to inform all coroutines waiting for a key to arrive on a put operation.
Actually, I would only need a coroutine compatible wait/notify primitives… hints?
Anyway, when I pause the threads during the lockup, I will get a stacktrace that may look like this one:
<15> ForkJoinPool.commonPool-worker-3"@830,030,709,776 in group "main": RUNNING
getNext:121, LockFreeLinkedListNode {kotlinx.coroutines.experimental.internal}
takeFirstReceiveOrPeekClosed:920, AbstractSendChannel {kotlinx.coroutines.experimental.channels}
offerInternal:54, AbstractSendChannel {kotlinx.coroutines.experimental.channels}
offerInternal:39, ConflatedChannel {kotlinx.coroutines.experimental.channels}
offerInternal:268, ConflatedBroadcastChannel$Subscriber {kotlinx.coroutines.experimental.channels}
offerInternal:239, ConflatedBroadcastChannel {kotlinx.coroutines.experimental.channels}
offer:219, ConflatedBroadcastChannel {kotlinx.coroutines.experimental.channels}
put:11, AwaitableMap {com.example}
Any ideas what’s going on here?
package com.example
import kotlinx.coroutines.experimental.channels.ConflatedBroadcastChannel
class AwaitableMap<K : Any, V : Any>(val delegateMap: MutableMap<K, V>) : MutableMap<K, V> by delegateMap {
val channel = ConflatedBroadcastChannel<K>()
override fun put(key: K, value: V): V? {
val putVal = delegateMap.put(key, value)
channel.offer(key)
return putVal
}
suspend fun await(key: K): V {
return delegateMap[key] ?: channel.open().use {
do {
val fetched = delegateMap[key]
if (fetched != null) {
return@use fetched
}
it.receive()
} while (true)
return@use null
}!!
}
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Kotlin ConflatedBroadcastChannel.offer() doesn't work?
See this. First case: val receivingChannel = MyRepository.myConflatedChannel.openSubscription() // then you can consume values using for example ...
Read more >"Channel was closed" Exception when other processes are ...
Noting for myself, but looks like this is an issue with using flow.collect vs flow.collectLatest , which stops the uireceiver from getting updated...
Read more >Change log for kotlinx.coroutines
Fixed a number of Channel and BroadcastChannel implementation bugs related to concurrent send/close/close of channels that lead to hanging send, offer or close ......
Read more >SharingCommand - Kotlin
Stops sharing, cancelling collection of the upstream flow, and resets the SharedFlow.replayCache to its initial state. The shareIn operator calls ...
Read more >LiveData, Flow, Channel.. why we need all these pipes?
offer() is a synchronous variant of send which backs off in situations when send ... val usersChannel = ConflatedBroadcastChannel<String?> ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fixed in
develop
branchIt turned out to be a whole complex of problems that happen when you concurrently close/send/close channels. It was also independently discovered by @cy6erGn0m