Skip to content

Commit dc44457

Browse files
committed
Add a warning if join is called and JobManager is suspended
Currently there is a situation that is really hard to notice but quite dangerous results. When the JobManager is suspended and one calls join() on a Job this is a no-op and it returns silently without even try to wait for the job as it could lead to deadlocks. Code using join in such situation will likely fail in an random way depending on if the job has already finished fast enough. This now adds a warning whenever this situation occurs to having a chance to be noticed and mitigated.
1 parent 5373ee3 commit dc44457

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

runtime/bundles/org.eclipse.core.jobs/src/org/eclipse/core/internal/jobs/JobManager.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,13 @@ protected boolean join(InternalJob job, long timeout, IProgressMonitor monitor)
10051005
}
10061006
//don't join a waiting or sleeping job when suspended (deadlock risk)
10071007
if (suspended && state != Job.RUNNING) {
1008+
String pluginId = JobOSGiUtils.getDefault().getBundleId(job);
1009+
if (pluginId == null) {
1010+
pluginId = JobManager.PI_JOBS;
1011+
}
1012+
RuntimeLog.log(new Status(IStatus.WARNING, pluginId, 0,
1013+
NLS.bind(JobMessages.JobManager_suspended_problem, job.getName()),
1014+
new IllegalStateException()));
10081015
return true;
10091016
}
10101017
//it's an error for a job to join itself

runtime/bundles/org.eclipse.core.jobs/src/org/eclipse/core/internal/jobs/JobMessages.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
public class JobMessages extends NLS {
2323
private static final String BUNDLE_NAME = "org.eclipse.core.internal.jobs.messages"; //$NON-NLS-1$
2424

25+
public static String JobManager_suspended_problem;
26+
2527
// Job Manager and Locks
2628
public static String jobs_blocked0;
2729
public static String jobs_blocked1;

runtime/bundles/org.eclipse.core.jobs/src/org/eclipse/core/internal/jobs/messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
### Runtime jobs plugin messages
1515

1616
### Job Manager and Locks
17+
JobManager_suspended_problem=Join was called on job \"{0}\" while JobManager is suspended, this will not work as expected\!
1718
jobs_blocked0=The user operation is waiting for background work to complete.
1819
jobs_blocked1=The user operation is waiting for \"{0}\" to complete.
1920
jobs_unblocked=The user operation is not waiting anymore.

0 commit comments

Comments
 (0)