From 3f7b9745b49990e95c32f73b77539c6046d2fe2d Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 11 Nov 2016 14:22:51 +0100 Subject: [PATCH] Fix race condition with synthetic files facade calculation in Upsource (UP-8046) --- .../kotlin/idea/caches/resolve/KotlinCacheServiceImpl.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/KotlinCacheServiceImpl.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/KotlinCacheServiceImpl.kt index 65673e90ecf..93bcdd76615 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/KotlinCacheServiceImpl.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/KotlinCacheServiceImpl.kt @@ -307,10 +307,15 @@ class KotlinCacheServiceImpl(val project: Project) : KotlinCacheService { } private fun getFacadeForSyntheticFiles(files: Set): ProjectResolutionFacade { - synchronized(syntheticFileCachesLock) { + val cachedValue = synchronized(syntheticFileCachesLock) { //NOTE: computations inside createCacheForSyntheticFiles depend on project root structure // so we additionally drop the whole slru cache on change - return CachedValuesManager.getManager(project).getCachedValue(project, syntheticFilesCacheProvider).get(files) + CachedValuesManager.getManager(project).getCachedValue(project, syntheticFilesCacheProvider) + } + // In Upsource, we create multiple instances of KotlinCacheService, which all access the same CachedValue instance (UP-8046) + // To avoid race conditions, we can't use the local lock to access the cached value contents. + synchronized(cachedValue) { + return cachedValue.get(files) } }