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

Correct improper usage of the SubMonitor #576

Merged
merged 1 commit into from
Dec 3, 2024

Conversation

ptziegler
Copy link
Contributor

From the documentation:

Since it is illegal to call beginTask on the same IProgressMonitor
more than once, the same instance of IProgressMonitor must not be
passed to convert more than once.

The proper way is to replace calls to IProgressMonitor.beginTask(...) with SubMonitor.convert(...), keep the SubMonitor as a local variable and use that from now on.

This amends commit 9009085.

@ptziegler
Copy link
Contributor Author

ptziegler commented Nov 29, 2024

I noticed that the target definition resolution usually gets stuck at 47%, which I believe is partially caused by a lot of funny stuff being done to the progress monitor when executing the download job...

image

Copy link
Contributor

@vogella vogella left a comment

Choose a reason for hiding this comment

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

I'm just looking via my phone but I assume that the done() call (and finally block) can be removed. See https://www.eclipse.org/articles/Article-Progress-Monitors/article.html

@vogella
Copy link
Contributor

vogella commented Nov 29, 2024

See section 5.7

@eclipse-equinox-bot
Copy link
Contributor

This pull request changes some projects for the first time in this development cycle.
Therefore the following files need a version increment:

bundles/org.eclipse.equinox.p2.artifact.repository/META-INF/MANIFEST.MF
bundles/org.eclipse.equinox.p2.discovery.compatibility/META-INF/MANIFEST.MF
bundles/org.eclipse.equinox.p2.discovery/META-INF/MANIFEST.MF
bundles/org.eclipse.equinox.p2.transport.ecf/META-INF/MANIFEST.MF
bundles/org.eclipse.equinox.p2.ui/META-INF/MANIFEST.MF
features/org.eclipse.equinox.p2.core.feature/feature.xml
features/org.eclipse.equinox.p2.discovery.feature/feature.xml
features/org.eclipse.equinox.p2.rcp.feature/feature.xml
features/org.eclipse.equinox.server.p2/feature.xml

An additional commit containing all the necessary changes was pushed to the top of this PR's branch. To obtain these changes (for example if you want to push more changes) either fetch from your fork or apply the git patch.

Git patch
From cb60c385cd6eb617309c4850a1bf401ea8458945 Mon Sep 17 00:00:00 2001
From: Eclipse Equinox Bot <[email protected]>
Date: Fri, 29 Nov 2024 20:15:05 +0000
Subject: [PATCH] Version bump(s) for 4.35.0 stream


diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.artifact.repository/META-INF/MANIFEST.MF
index 5df6b28dc..183253da8 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.equinox.p2.artifact.repository;singleton:=true
-Bundle-Version: 1.5.500.qualifier
+Bundle-Version: 1.5.600.qualifier
 Bundle-Activator: org.eclipse.equinox.internal.p2.artifact.repository.Activator
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin
diff --git a/bundles/org.eclipse.equinox.p2.discovery.compatibility/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.discovery.compatibility/META-INF/MANIFEST.MF
index 46e7c9394..c4ecf6956 100644
--- a/bundles/org.eclipse.equinox.p2.discovery.compatibility/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.discovery.compatibility/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: %Bundle-Name
 Bundle-SymbolicName: org.eclipse.equinox.p2.discovery.compatibility;singleton:=true
-Bundle-Version: 1.3.500.qualifier
+Bundle-Version: 1.3.600.qualifier
 Bundle-Vendor: %Bundle-Vendor
 Bundle-RequiredExecutionEnvironment: JavaSE-17
 Require-Bundle: org.eclipse.core.runtime;bundle-version="3.29.0",
diff --git a/bundles/org.eclipse.equinox.p2.discovery/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.discovery/META-INF/MANIFEST.MF
index e0e2f5139..d494b0bf4 100644
--- a/bundles/org.eclipse.equinox.p2.discovery/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.discovery/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: %Bundle-Name
 Bundle-SymbolicName: org.eclipse.equinox.p2.discovery;singleton:=true
-Bundle-Version: 1.3.400.qualifier
+Bundle-Version: 1.3.500.qualifier
 Bundle-Vendor: %Bundle-Vendor
 Bundle-RequiredExecutionEnvironment: JavaSE-17
 Require-Bundle: org.eclipse.core.runtime;bundle-version="3.29.0",
diff --git a/bundles/org.eclipse.equinox.p2.transport.ecf/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.transport.ecf/META-INF/MANIFEST.MF
index 6e526b259..453d5aafa 100644
--- a/bundles/org.eclipse.equinox.p2.transport.ecf/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.transport.ecf/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.equinox.p2.transport.ecf
-Bundle-Version: 1.4.300.qualifier
+Bundle-Version: 1.4.400.qualifier
 Bundle-RequiredExecutionEnvironment: JavaSE-17
 Require-Bundle: org.eclipse.ecf;bundle-version="3.1.0",
  org.eclipse.ecf.filetransfer;bundle-version="4.0.0",
diff --git a/bundles/org.eclipse.equinox.p2.ui/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.ui/META-INF/MANIFEST.MF
index cdb0eafd6..f41eefc5a 100644
--- a/bundles/org.eclipse.equinox.p2.ui/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.ui/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: %bundleName
 Bundle-SymbolicName: org.eclipse.equinox.p2.ui;singleton:=true
-Bundle-Version: 2.8.600.qualifier
+Bundle-Version: 2.8.700.qualifier
 Bundle-Activator: org.eclipse.equinox.internal.p2.ui.ProvUIActivator
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin
diff --git a/features/org.eclipse.equinox.p2.core.feature/feature.xml b/features/org.eclipse.equinox.p2.core.feature/feature.xml
index 19d9553ee..973054bd0 100644
--- a/features/org.eclipse.equinox.p2.core.feature/feature.xml
+++ b/features/org.eclipse.equinox.p2.core.feature/feature.xml
@@ -2,7 +2,7 @@
 <feature
       id="org.eclipse.equinox.p2.core.feature"
       label="%featureName"
-      version="1.7.400.qualifier"
+      version="1.7.500.qualifier"
       provider-name="%providerName"
       license-feature="org.eclipse.license"
       license-feature-version="0.0.0">
diff --git a/features/org.eclipse.equinox.p2.discovery.feature/feature.xml b/features/org.eclipse.equinox.p2.discovery.feature/feature.xml
index bfa9ebe7a..d6ddedad9 100644
--- a/features/org.eclipse.equinox.p2.discovery.feature/feature.xml
+++ b/features/org.eclipse.equinox.p2.discovery.feature/feature.xml
@@ -2,7 +2,7 @@
 <feature
       id="org.eclipse.equinox.p2.discovery.feature"
       label="%featureName"
-      version="1.3.600.qualifier"
+      version="1.3.700.qualifier"
       provider-name="%providerName"
       license-feature="org.eclipse.license"
       license-feature-version="0.0.0">
diff --git a/features/org.eclipse.equinox.p2.rcp.feature/feature.xml b/features/org.eclipse.equinox.p2.rcp.feature/feature.xml
index a65e4e7dd..a30608518 100644
--- a/features/org.eclipse.equinox.p2.rcp.feature/feature.xml
+++ b/features/org.eclipse.equinox.p2.rcp.feature/feature.xml
@@ -2,7 +2,7 @@
 <feature
       id="org.eclipse.equinox.p2.rcp.feature"
       label="%featureName"
-      version="1.4.2600.qualifier"
+      version="1.4.2700.qualifier"
       provider-name="%providerName"
       license-feature="org.eclipse.license"
       license-feature-version="0.0.0">
diff --git a/features/org.eclipse.equinox.server.p2/feature.xml b/features/org.eclipse.equinox.server.p2/feature.xml
index bd6fdc122..9ef0f7d0c 100644
--- a/features/org.eclipse.equinox.server.p2/feature.xml
+++ b/features/org.eclipse.equinox.server.p2/feature.xml
@@ -2,7 +2,7 @@
 <feature
       id="org.eclipse.equinox.server.p2"
       label="%featureName"
-      version="1.12.1500.qualifier"
+      version="1.12.1600.qualifier"
       provider-name="%providerName"
       license-feature="org.eclipse.license"
       license-feature-version="0.0.0">
-- 
2.47.0

Further information are available in Common Build Issues - Missing version increments.

@ptziegler ptziegler force-pushed the sub-monitor branch 2 times, most recently from b842ec3 to 353f88e Compare November 29, 2024 20:32
@ptziegler
Copy link
Contributor Author

ptziegler commented Nov 29, 2024

I'm just looking via my phone but I assume that the done() call (and finally block) can be removed. See https://www.eclipse.org/articles/Article-Progress-Monitors/article.html

Technically yes, but I think my mistake was that the call to done() still needs to be done for the main monitor. Meaning the calls in the finally block should remain monitor.done().

It is not necessary to call done() on the result, but the caller is responsible for calling done() on the argument.

Copy link

github-actions bot commented Nov 29, 2024

Test Results

  375 files  +  124    375 suites  +124   48m 9s ⏱️ + 17m 32s
1 904 tests +    6  1 901 ✅ +    6  3 💤 ±0  0 ❌ ±0 
6 712 runs  +2 208  6 703 ✅ +2 205  9 💤 +3  0 ❌ ±0 

Results for commit b131c75. ± Comparison against base commit 7eb2f50.

♻️ This comment has been updated with latest results.

try {
for (AbstractDiscoveryStrategy discoveryStrategy : discoveryStrategies) {
if (monitor.isCanceled()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this extra check necessary? We do a split (which auto checks for cancellations ) just a few lines later

Copy link
Member

Choose a reason for hiding this comment

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

Is this extra check necessary? We do a split (which auto checks for cancellations ) just a few lines later

This is not completely the same. In one case you can silently return in the other an exception is thrown.

Copy link
Contributor

Choose a reason for hiding this comment

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

Split also throws this exception

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's true. But given that the method is supposed to return gracefully upon cancellation, rather than throwing an exception, I should use newChild() rather than split().

IPlanner planner = ui.getSession().getProvisioningAgent().getService(IPlanner.class);
try {
Set<IInstallableUnit> allUpdates = new HashSet<>();
for (IInstallableUnit unit : iusToUpdate) {
if (monitor.isCanceled())
if (subMonitor.isCanceled())
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This whole if check can go, given that the OperationCanceledException is explicitly caught. In both cases, Collector.emptyCollector() is returned.

@laeubi
Copy link
Member

laeubi commented Nov 30, 2024

It is not necessary to call done() on the result, but the caller is responsible for calling done() on the argument

I think this refers to the "top most caller" that is the one that created the monitor / acquired it for the first time. For a Job I would expect that the job framework is calling done() after the job is finished.

@vogella
Copy link
Contributor

vogella commented Nov 30, 2024

Yes to @laeubi statement of the done call. If you don't create the monitor you do not have to call done

@vogella
Copy link
Contributor

vogella commented Nov 30, 2024

@ptziegler we have also tracing to find incorrect usage of progress monitoring, see the article (search for tracing).

Years ago @kthoms and I a spend lot of time trying to clean the usage up in platform and pde but there were to many to fix them all .

@ptziegler
Copy link
Contributor Author

I've removed the try-finally blocks that only serve to call monitor.done(). I've also replaced most calls to SubMonitor.split() with SubMonitor.newChild() because most methods are expected to return gracefully and therefore an OperationCanceledException must not be thrown.

we have also tracing to find incorrect usage of progress monitoring, see the article (search for tracing).

Looks interesting. Perhaps I can give it a go later on. It wouldn't surprise me if there are other places where the SubProgressMonitor was replaced too eagerly.

@vogella
Copy link
Contributor

vogella commented Dec 3, 2024

@ptziegler is this ready to be merged from your side?

@ptziegler
Copy link
Contributor Author

@ptziegler is this ready to be merged from your side?

Yes. From my side, I'm done.

> Since it is illegal to call beginTask on the same IProgressMonitor
> more than once, the same instance of IProgressMonitor must not be
> passed to convert more than once.

The proper way is to replace calls to IProgressMonitor.beginTask(...)
with SubMonitor.convert(...), keep the SubMonitor as a local variable
and use that from now on.

This amends commit 9009085.
@vogella
Copy link
Contributor

vogella commented Dec 3, 2024

Build works fine with GH actions. The Jenkins build is also successful but fail after the build in the publish bit, which seems unrelated.

05:45:15 [INFO] ------------------------------------------------------------------------
05:45:15 [INFO] BUILD SUCCESS
05:45:15 [INFO] ------------------------------------------------------------------------
05:45:15 [INFO] Total time: 20:56 min (Wall Clock)
05:45:15 [INFO] Finished at: 2024-12-03T10:45:15Z
05:45:15 [INFO] ------------------------------------------------------------------------
[Pipeline] }

@vogella vogella merged commit 1a42e02 into eclipse-equinox:master Dec 3, 2024
11 of 12 checks passed
@vogella
Copy link
Contributor

vogella commented Dec 3, 2024

Thanks @ptziegler, looking forward for tomorrow I-build improved target platform resolution

@ptziegler ptziegler deleted the sub-monitor branch December 3, 2024 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants