From c25ca687708effc6ff5720415ff2d886b310dbbb Mon Sep 17 00:00:00 2001 From: Roman Golyshev Date: Fri, 20 Feb 2026 13:32:04 +0100 Subject: [PATCH] KTIJ-37664 [kotlin] Use `dropSynchronously` in `KtCompilerPluginsProviderIdeImpl` to drop `pluginsCacheCachedValue` This allows the explicit disposal of `KtCompilerPluginsProviderIdeImpl` to wait until the initialization of `pluginsCacheCachedValue` has finished. It is not the best solution, because ideally, nobody from the outside should call the `dispose` function directly on their own. Unfortunately, `kotlin-rpc` plugin has to do that at the moment, since it has to download jars with compiler plugins from the network, and at some point should be able to present a renewed versions of bundled jars from its `KotlinBundledFirCompilerPluginProvider` implementation. To address that in the future, please see KTIJ-37667. ^KTIJ-37664 Fixed GitOrigin-RevId: 867ebe0d1d8df902d1f6ecd5ec6b2cc7f5b54999 --- .../fir/extensions/KtCompilerPluginsProviderIdeImpl.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plugins/kotlin/fir/src/org/jetbrains/kotlin/idea/fir/extensions/KtCompilerPluginsProviderIdeImpl.kt b/plugins/kotlin/fir/src/org/jetbrains/kotlin/idea/fir/extensions/KtCompilerPluginsProviderIdeImpl.kt index 1559321c31b8..e35982e2981c 100644 --- a/plugins/kotlin/fir/src/org/jetbrains/kotlin/idea/fir/extensions/KtCompilerPluginsProviderIdeImpl.kt +++ b/plugins/kotlin/fir/src/org/jetbrains/kotlin/idea/fir/extensions/KtCompilerPluginsProviderIdeImpl.kt @@ -103,9 +103,16 @@ internal class KtCompilerPluginsProviderIdeImpl( /** * Throws away the cache for all the registered plugins, and executes all the disposables * registered in the corresponding [CompilerPluginRegistrar.ExtensionStorage]s. + * + * Note: we drop the [pluginsCacheCachedValue] synchronously, so that + * the [KtCompilerPluginsCache.new] call and all the calls to [KotlinBundledFirCompilerPluginProvider.provideBundledPluginJar] in it + * either have not yet started, or have already completed. + * + * Otherwise, race conditions similar to KTIJ-37664 may occur. */ private fun resetPluginsCache() { - pluginsCacheCachedValue.drop()?.dispose() + val cache = pluginsCacheCachedValue.dropSynchronously() + cache?.dispose() } companion object {