avoid attach listener/write action race which could lead to unresponsiveness

When we try to attach app listener in the unfortunate moment between application firing beforeWriteActionStart() and actual write action start, all attached listeners won't be fired during this write action.
To avoid that, we check that if after attaching listener the app is still trying to start write action, then we declare the moment
unfortunate, detach listener and try again.
This commit is contained in:
Alexey Kudravtsev
2017-07-27 14:27:05 +03:00
parent ff11452e25
commit 9a423e5931
@@ -451,10 +451,17 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp
while (true) {
Disposable disposable = Disposer.newDisposable();
ProgressIndicator wrapper = new SensitiveProgressWrapper(progressIndicator);
wrapper.start();
ProgressIndicatorUtils.forceWriteActionPriority(wrapper, disposable);
try {
// avoid "attach listener"/"write action" race
ReadAction.run(() -> {
wrapper.start();
ProgressIndicatorUtils.forceWriteActionPriority(wrapper, disposable);
// there is a chance we are racing with write action, in which case just registered listener might not be called, retry.
if (ApplicationManagerEx.getApplicationEx().isWriteActionPending()) {
throw new ProcessCanceledException();
}
});
// use wrapper here to cancel early when write action start but do not affect the original indicator
((JobLauncherImpl)JobLauncher.getInstance()).processQueue(filesToInspect, filesFailedToInspect, wrapper, TOMBSTONE, processor);
break;