From a787494c69f16396daaefa46e8a13aa7815377d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Doln=C3=ADk?= Date: Thu, 16 May 2024 15:43:11 +0200 Subject: [PATCH] Fix a thread leak that prevented the compilation from finishing when using kotlin.native.disableCompilerDaemon. --- .../analytics/performance/SkiePerformanceAnalytics.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/analytics/performance/SkiePerformanceAnalytics.kt b/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/analytics/performance/SkiePerformanceAnalytics.kt index 019e4eb7f..bbc020f69 100644 --- a/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/analytics/performance/SkiePerformanceAnalytics.kt +++ b/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/analytics/performance/SkiePerformanceAnalytics.kt @@ -8,7 +8,9 @@ import kotlinx.coroutines.asCoroutineDispatcher import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext import kotlinx.serialization.Serializable -import java.util.concurrent.Executors +import java.util.concurrent.LinkedBlockingQueue +import java.util.concurrent.ThreadPoolExecutor +import java.util.concurrent.TimeUnit import kotlin.coroutines.CoroutineContext import kotlin.time.Duration import kotlin.time.DurationUnit @@ -22,7 +24,9 @@ object SkiePerformanceAnalytics { private val rootConfiguration: RootConfiguration, ) : AnalyticsProducer { - private val dispatcher: CoroutineContext = Executors.newSingleThreadExecutor().asCoroutineDispatcher() + private val threadExecutor = ThreadPoolExecutor(0, 1, 1, TimeUnit.MINUTES, LinkedBlockingQueue()) + + private val dispatcher: CoroutineContext = threadExecutor.asCoroutineDispatcher() override val name: String = "skie-performance" @@ -39,6 +43,8 @@ object SkiePerformanceAnalytics { collected = true + threadExecutor.setKeepAliveTime(1, TimeUnit.SECONDS) + entries.toPrettyJson() }