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

Fix race condition in ThreadJob.waitForRun #659 #661

Merged
merged 1 commit into from
Sep 29, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,17 @@ public void testIndividualProjectBuilds_ProjectRelaxedRule() throws Exception {
});
}

@Test
public void testIndividualProjectBuilds_WithManyProjects_ProjectRelaxedRule() throws Exception {
int numberOfParallelBuilds = 60;
jukzi marked this conversation as resolved.
Show resolved Hide resolved
var longRunningProjects = createMultipleTestProjects(numberOfParallelBuilds, BuildDurationType.LONG_RUNNING,
RuleType.CURRENT_PROJECT_RELAXED);
executeIndividualFullProjectBuilds(numberOfParallelBuilds, () -> {
assertBuildsToStart(getAllProjects());
assertMinimumNumberOfSimultaneousBuilds(longRunningProjects.size());
});
}

@Test
public void testWorkspaceBuild_NoConflictRule() throws Exception {
int numberOfParallelBuilds = 3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@

import java.util.List;
import org.eclipse.core.internal.runtime.RuntimeLog;
import org.eclipse.core.runtime.*;
import org.eclipse.core.runtime.jobs.*;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.jobs.LockListener;

/**
* Captures the implicit job state for a given thread.
Expand Down Expand Up @@ -317,11 +323,19 @@ private static ThreadJob waitForRun(final ThreadJob threadJob, IProgressMonitor
// The actual exit conditions are listed above at the beginning of
// this while loop
int state = blockingJob.getState();
//ensure we don't wait forever if the blocker is waiting, because it might have yielded to me
if (state == Job.RUNNING && canBlock) {
blockingJob.jobStateLock.wait();
} else if (state != Job.NONE) {
blockingJob.jobStateLock.wait(250);
// Check that blockingJob has not acquired a different, non-conflicting
// scheduling rule since checking for conflicts by JobManager. This can
// particularly happen if blockingJob is a ThreadJob that is reused for the
// same thread across the acquisition of different rules (see ThreadJob::recycle
// and ImplicitJob::newThreadJob) via JobManager::beginRule.
if (state != Job.NONE && blockingJob.isConflicting(threadJob)) {
// ensure we don't wait forever if the blocker is waiting, because it might have
// yielded to me
if (state == Job.RUNNING && canBlock) {
blockingJob.jobStateLock.wait();
jukzi marked this conversation as resolved.
Show resolved Hide resolved
} else {
blockingJob.jobStateLock.wait(250);
}
}
} catch (InterruptedException e) {
// This thread may be interrupted via two common scenarios. 1) If
Expand Down
Loading