Skip to content

Kotlin Compiler 2.3.20 can cause OOMs by unstopped coroutines Dispatcher threads #2817

@antohaby

Description

@antohaby

Hi,

Recently in kotlin 2.3.20 we've discovered a preformance issue (https://youtrack.jetbrains.com/projects/KT/issues/KT-84152) that can affect KSP as well.

TL;DR: kotlin frontend unexpectedly spawn coroutines Default Dispatcher thread and doesn't stop it. When using isolated classloaders it will make them unclean-able by GC. So manual Dispatchers.shutdown is required.

This particular code:

var isolatedClassLoaderCache = mutableMapOf<String, URLClassLoader>()

May cause OOMs in large builds that actively use KSP.

You may need to improve classloader cache by adding some timeout so it can call "Dispatchers.shutdown", or you can fix this issue by creating a parent classloader with kotlinx coroutines and share it with all KSP tasks.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions