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

Lazy coroutine stays in DebugProbes output if never started #2294

Closed
timurstrekalov opened this issue Oct 10, 2020 · 0 comments
Closed

Lazy coroutine stays in DebugProbes output if never started #2294

timurstrekalov opened this issue Oct 10, 2020 · 0 comments
Assignees
Labels

Comments

@timurstrekalov
Copy link

When a coroutine with start = CoroutineStart.LAZY is cancelled before ever starting, DebugProbes seems to keep them around forever.

Example:

import kotlinx.coroutines.*
import kotlinx.coroutines.debug.DebugProbes

object Main {

    @JvmStatic
    fun main(args: Array<String>): Unit = runBlocking {
        DebugProbes.enableCreationStackTraces = false
        DebugProbes.install()

        val job = launch(start = CoroutineStart.LAZY) {
            delay(Long.MAX_VALUE)
        }
        job.invokeOnCompletion { println("job stopped: ${it?.message}") }

        job.cancel("foo")
        job.join()

        DebugProbes.dumpCoroutines(System.out)
    }
}

Output:

job stopped: foo
Coroutines dump 2020/10/10 13:52:45

Coroutine LazyStandaloneCoroutine{Cancelled}@26b3fd41, state: CREATED
	(Coroutine creation stacktrace)
Process finished with exit code 0

Note that if that lazy job is ever started, it gets correctly removed.

Example with start = CoroutineStart.DEFAULT:

import kotlinx.coroutines.*
import kotlinx.coroutines.runBlocking

object Main {

    @JvmStatic
    fun main(args: Array<String>): Unit = runBlocking {
        DebugProbes.enableCreationStackTraces = false
        DebugProbes.install()

        val job = launch {
            delay(Long.MAX_VALUE)
        }
        job.invokeOnCompletion { println("job stopped: ${it?.message}") }

        job.cancel("foo")
        job.join()

        DebugProbes.dumpCoroutines(System.out)
    }
}

Output:

job stopped: foo
Coroutines dump 2020/10/10 13:52:29
Process finished with exit code 0
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