mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
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:
+9
-2
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user