Skip to content

CoroutineDispatcher isActive after cancel() since 1.7.0 #3967

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
Doctoror opened this issue Dec 1, 2023 · 3 comments
Closed

CoroutineDispatcher isActive after cancel() since 1.7.0 #3967

Doctoror opened this issue Dec 1, 2023 · 3 comments
Labels

Comments

@Doctoror
Copy link

Doctoror commented Dec 1, 2023

Describe the bug
Since 1.7.0, CoroutineDispatcher isActive is still true after cancel()

Provide a Reproducer

@Test
fun dispatcherIsNotActiveAfterCancellation() = runTest {
    val dispatcher = Dispatchers.Default // same for UnconfinedTestDispatcher or any other
    dispatcher.cancel()
    assertFalse(dispatcher.isActive)
}

org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4 - test passes
org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.0 - AssertionError (same for v1.7.3, which is currently the latest stable)

@Doctoror Doctoror added the bug label Dec 1, 2023
@psteiger
Copy link

psteiger commented Dec 4, 2023

CoroutineDispather.cancel() is a call that does not make sense here: it resolves to CoroutineContext.cancel() (because every CoroutineContext.Element is a CoroutineContext itself).

The call checks for a Job in the context and cancels it if it's present. A dispatcher never has a Job (at least not the dispatchers shipped with the library, not sure if they even can have a Job).

The behavior change stems from #3300: isActive now returns true when a job is not present in context.

@dkhalanskyjb
Copy link
Collaborator

Yep, not a bug, just some very weird code.

@dkhalanskyjb dkhalanskyjb closed this as not planned Won't fix, can't repro, duplicate, stale Dec 5, 2023
@Doctoror
Copy link
Author

Doctoror commented Dec 5, 2023

Thank you, @psteiger. Your comment and the linked change explains everything.

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

3 participants