Skip to content

Memory leak with new memory model and withTimeout #3351

@qwwdfsad

Description

@qwwdfsad

See https://youtrack.jetbrains.com/issue/KTOR-4298 for details.

The root cause is our dispatcher implementation:


override fun invokeOnTimeout(timeMillis: Long, block: Runnable, context: CoroutineContext): DisposableHandle {
    // No API to cancel on timeout
    worker.executeAfter(timeMillis.toMicrosSafe()) { block.run() }
    return NonDisposableHandle
}

Yet it can be workarounded by carefully replacing lambda with something holding an atomic reference to a block so it can be nulled out

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions