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

[JENKINS-41127] Prevent flyweight tasks for jobs with concurrent execution disabled from running concurrently #3562

Merged
merged 2 commits into from
Aug 4, 2018
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
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/Queue.java
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,7 @@ public void maintain() {
{// update parked (and identify any pending items whose executor has disappeared)
List<BuildableItem> lostPendings = new ArrayList<BuildableItem>(pendings);
for (Computer c : jenkins.getComputers()) {
for (Executor e : c.getExecutors()) {
for (Executor e : c.getAllExecutors()) {
if (e.isInterrupted()) {
// JENKINS-28840 we will deadlock if we try to touch this executor while interrupt flag set
// we need to clear lost pendings as we cannot know what work unit was on this executor
Expand Down
26 changes: 26 additions & 0 deletions test/src/test/java/hudson/model/QueueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;

import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.*;
import org.junit.Ignore;
Expand Down Expand Up @@ -458,6 +459,31 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
assert task.exec instanceof OneOffExecutor : task.exec;
}

@Issue("JENKINS-41127")
@Test public void flyweightTasksUnwantedConcurrency() throws Exception {
Label label = r.jenkins.getSelfLabel();
AtomicInteger cnt = new AtomicInteger();
TestFlyweightTask task1 = new TestFlyweightTask(cnt, label);
TestFlyweightTask task2 = new TestFlyweightTask(cnt, label);
assertFalse(task1.isConcurrentBuild());
assertFalse(task2.isConcurrentBuild());
// We need to call Queue#maintain without any interleaving Queue modification to reproduce the issue.
Queue.withLock(() -> {
r.jenkins.getQueue().schedule2(task1, 0);
r.jenkins.getQueue().maintain();
Queue.Item item1 = r.jenkins.getQueue().getItem(task1);
assertThat(r.jenkins.getQueue().getPendingItems(), contains(item1));
r.jenkins.getQueue().schedule2(task2, 0);
r.jenkins.getQueue().maintain();
Queue.Item item2 = r.jenkins.getQueue().getItem(task2);
// Before the fix, item1 would no longer be present in the pending items (but would
// still be assigned to a live executor), and item2 would not be blocked, which would
// allow the tasks to execute concurrently.
assertThat(r.jenkins.getQueue().getPendingItems(), contains(item1));
assertTrue(item2.isBlocked());
});
}

@Issue("JENKINS-27256")
@Test public void inQueueTaskLookupByAPI() throws Exception {
FreeStyleProject p = r.createFreeStyleProject();
Expand Down