Fix freeze during script definitions update (KT-32513)
loadScriptDefinitions is a long running operation, so it shouldn't be called under write lock. This may cause a freeze when someone else wants to get definitions from the same loader during loading process ^KT-32513 Fixed
This commit is contained in:
@@ -76,10 +76,15 @@ abstract class AsyncScriptDefinitionsContributor(protected val project: Project)
|
||||
shouldStartNewUpdate = false
|
||||
}
|
||||
|
||||
val wasRunning = definitionsLock.isWriteLocked
|
||||
val previousDefinitions = definitionsLock.read {
|
||||
if (!forceStartUpdate && _definitions != null) return
|
||||
|
||||
_definitions
|
||||
}
|
||||
|
||||
val newDefinitions = loadScriptDefinitions(previousDefinitions)
|
||||
|
||||
val needReload = definitionsLock.write {
|
||||
if (wasRunning && !forceStartUpdate && _definitions != null) return@write false
|
||||
val newDefinitions = loadScriptDefinitions(_definitions)
|
||||
if (newDefinitions != _definitions) {
|
||||
_definitions = newDefinitions
|
||||
return@write true
|
||||
|
||||
Reference in New Issue
Block a user