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

tryReleaseClaimedContinuation: java.lang.IllegalStateException: Inconsistent state #2768

Closed
qwwdfsad opened this issue Jun 16, 2021 · 0 comments
Assignees
Labels

Comments

@qwwdfsad
Copy link
Member

Reproducer:

class Reproducer  {
    @Test
    fun run() = runBlocking<Unit> {
        CoroutineScope(EmptyCoroutineContext).launch {
            runStressTest()
        }.join()
    }

    suspend fun runStressTest() = withContext(Dispatchers.Default) {
        repeat(1000) { a ->
            repeat(100) { b ->
                launch {
                    runStressTestOnce((a + 1) * 10, (b + 1) * 10)
                }
            }
        }
    }

    suspend fun runStressTestOnce(delay: Int, debounce: Int) = coroutineScope {
        val stateflow = MutableStateFlow(0)
        launch {
            repeat(Integer.MAX_VALUE) { i ->
                stateflow.emit(i)
                delay(delay.toLong())
            }
        }
        var last = 0
        stateflow.debounce(debounce.toLong()).collect { i ->
            if (i - last > 100) {
                println("${delay}x${debounce} => $i")
                last = i
            }
        }
    }
}

Originally reported by @denis-bezrukov in #2736

@qwwdfsad qwwdfsad added the bug label Jun 16, 2021
@qwwdfsad qwwdfsad self-assigned this Jun 16, 2021
qwwdfsad added a commit that referenced this issue Jun 18, 2021
…nes and await for reusability to have a consistent state

Fixes #2736
Fixes #2768
pablobaxter pushed a commit to pablobaxter/kotlinx.coroutines that referenced this issue Sep 14, 2022
Kotlin#2772)

* Properly detect non-released reusable continuations in non-reusable ones and await for reusability to have a consistent state
* Ensure that the caller to DispatchedContinuation.isReusable is reusable itself
* Using the previous invariant, simplify DispatchedContinuation.isReusable to a single null-check
* It also restores the invariant that `cc.isReusable() == cc.resumeMode.isReusableMode`

Fixes Kotlin#2736
Fixes Kotlin#2768
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

1 participant