Fix race condition with synthetic files facade calculation in Upsource (UP-8046)

This commit is contained in:
Dmitry Jemerov
2016-11-11 14:22:51 +01:00
parent b96deac09c
commit 3f7b9745b4
@@ -307,10 +307,15 @@ class KotlinCacheServiceImpl(val project: Project) : KotlinCacheService {
}
private fun getFacadeForSyntheticFiles(files: Set<KtFile>): 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)
}
}