Skip to content

Commit

Permalink
Merge pull request #504 from panicking/fix-topic-cancelling-patches
Browse files Browse the repository at this point in the history
Fix  [JENKINS-70162]   [JENKINS-72193]   [JENKINS-70539]   [JENKINS-69338] Fix topic cancelling patches (this close races in abortBuild)
  • Loading branch information
rsandell authored Mar 8, 2024
2 parents 374391c + f410332 commit 6fe554e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,17 @@ public void gerritEvent(GerritEvent event) {
}
if (event instanceof GerritTriggeredEvent) {
GerritTriggeredEvent triggeredEvent = (GerritTriggeredEvent)event;
if (t.isInteresting(triggeredEvent)) {
logger.trace("The event is interesting.");
abortBuild(t, triggeredEvent);
if (t.isOnlyAbortRunningBuild(triggeredEvent)) {
logger.trace("Just aborting build based on event not scheduling new one.");
return;
synchronized (this) {
if (t.isInteresting(triggeredEvent)) {
logger.trace("The event is interesting.");
abortBuild(t, triggeredEvent);
if (t.isOnlyAbortRunningBuild(triggeredEvent)) {
logger.trace("Just aborting build based on event not scheduling new one.");
return;
}
notifyOnTriggered(t, triggeredEvent);
schedule(t, new GerritCause(triggeredEvent, t.isSilentMode()), triggeredEvent);
}
notifyOnTriggered(t, triggeredEvent);
schedule(t, new GerritCause(triggeredEvent, t.isSilentMode()), triggeredEvent);
}
}
}
Expand Down Expand Up @@ -162,15 +164,17 @@ public void gerritEvent(ManualPatchsetCreated event) {
// to just return now without processing the event.
return;
}
if (t.isInteresting(event)) {
logger.trace("The event is interesting.");
abortBuild(t, event);
if (t.isOnlyAbortRunningBuild(event)) {
logger.trace("Just aborting build based on event not scheduling new one.");
return;
synchronized (this) {
if (t.isInteresting(event)) {
logger.trace("The event is interesting.");
abortBuild(t, event);
if (t.isOnlyAbortRunningBuild(event)) {
logger.trace("Just aborting build based on event not scheduling new one.");
return;
}
notifyOnTriggered(t, event);
schedule(t, new GerritManualCause(event, t.isSilentMode()), event);
}
notifyOnTriggered(t, event);
schedule(t, new GerritManualCause(event, t.isSilentMode()), event);
}
}

Expand Down Expand Up @@ -206,15 +210,17 @@ public void gerritEvent(CommentAdded event) {
// to just return now without processing the event.
return;
}
if (t.isInteresting(event) && t.commentAddedMatch(event)) {
logger.trace("The event is interesting.");
abortBuild(t, event);
if (t.isOnlyAbortRunningBuild(event)) {
logger.trace("Just aborting build based on event not scheduling new one.");
return;
synchronized (this) {
if (t.isInteresting(event) && t.commentAddedMatch(event)) {
logger.trace("The event is interesting.");
abortBuild(t, event);
if (t.isOnlyAbortRunningBuild(event)) {
logger.trace("Just aborting build based on event not scheduling new one.");
return;
}
notifyOnTriggered(t, event);
schedule(t, new GerritCause(event, t.isSilentMode()), event);
}
notifyOnTriggered(t, event);
schedule(t, new GerritCause(event, t.isSilentMode()), event);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import hudson.model.Computer;
import hudson.model.Executor;
import hudson.model.Item;
import hudson.model.Job;
import hudson.model.Queue;
import hudson.model.Result;
import hudson.model.Run;
Expand Down Expand Up @@ -242,7 +243,8 @@ private void cancelMatchingJobs(GerritTriggeredEvent event, String jobName, Caus
List<Queue.Item> itemsInQueue = Queue.getInstance().getItems((Queue.Task)getJob());
for (Queue.Item item : itemsInQueue) {
if (checkCausedByGerrit(event, item.getCauses())) {
if (jobName.equals(item.task.getName())) {
Job tJob = (Job)item.task;
if (jobName.equals(tJob.getFullName())) {
Queue.getInstance().cancel(item);
}
}
Expand Down

0 comments on commit 6fe554e

Please sign in to comment.