question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ConflatedBroadcastChannel hangs in offer()

See original GitHub issue

Hi 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:closed
  • Created 6 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
elizarovcommented, Jun 6, 2017

Fixed in develop branch

0reactions
elizarovcommented, Jun 7, 2017

It 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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found