Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 578871 - prevent UI freeze during UNDO operation + autobuild #6

Merged
merged 1 commit into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,20 @@
import org.eclipse.core.commands.operations.IUndoContext;
import org.eclipse.core.commands.operations.IUndoableOperation;
import org.eclipse.core.commands.operations.OperationHistoryEvent;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Adapters;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.jobs.IJobManager;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.LegacyActionTools;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IPartListener;
Expand Down Expand Up @@ -298,7 +303,27 @@ public final void run() {
if (getOperation() instanceof IAdvancedUndoableOperation2) {
runInBackground = ((IAdvancedUndoableOperation2) getOperation()).runInBackground();
}
progressDialog.run(runInBackground, true, runnable);
if (runInBackground) {
progressDialog.run(runInBackground, true, runnable);
} else {
// prevent UI freeze during AutoBuild as in
// org.eclipse.jdt.internal.ui.refactoring.RefactoringExecutionHelper#perform
final IJobManager manager = Job.getJobManager();
// pessimistic scheduling rule:
final ISchedulingRule rule = ResourcesPlugin.getWorkspace().getRoot();
try {
try {
// interrupt autobuild or show Wait/Cancel Dialog:
Runnable r = () -> manager.beginRule(rule, null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change causes a regression. If the Undo task joins on a workspace rule, it hangs now.
So starting a rule here is not OK.
I would propose to revert the change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the Undo task joins on a workspace rule

how to reproduce that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have custom IUndoableOperation (we have one that extends AbstractOperation) that runs operation in a different thread and there takes the workspace rule.

    @Override
    public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {

        IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
        try {
            progressService.run(true, false, new IRunnableWithProgress() {
                @Override
                public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    ISchedulingRule rule = ResourcesPlugin.getWorkspace().getRoot();
                   Job.getJobManager().beginRule(rule, monitor); // here we hang now
                   // ... do something that needs workspace
                }
            });
        } catch (InvocationTargetException | InterruptedException e) {
        }

        return Status.OK_STATUS;
    }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, locking anything accessible to 3rd party code before starting undo is not OK, because "undo" in 3rd party code can require the same lock.

Also interesting (I haven't noticed that first), that the org.eclipse.ui.workbench bundle in question had no references to org.eclipse.core.resources bundle before, I think for a good reason.

BusyIndicator.showWhile(parent.getDisplay(), r);
} catch (OperationCanceledException e) {
throw new InterruptedException(e.getMessage());
}
progressDialog.run(runInBackground, true, runnable); // <-- actual work
} finally {
manager.endRule(rule);
}
}
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
if (t == null) {
Expand Down
3 changes: 2 additions & 1 deletion bundles/org.eclipse.ui.workbench/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.19.0,4.0.0)",
org.eclipse.emf.ecore;bundle-version="2.7.0",
org.eclipse.e4.ui.services;bundle-version="1.3.0",
org.eclipse.emf.ecore.xmi;bundle-version="2.11.0",
org.eclipse.e4.core.di.extensions;bundle-version="0.13.0"
org.eclipse.e4.core.di.extensions;bundle-version="0.13.0",
org.eclipse.core.resources;bundle-version="3.17.0"
Import-Package: com.ibm.icu.util,
javax.annotation,
javax.inject;version="1.0.0",
Expand Down