Skip to content

Commit 05a26da

Browse files
committedAug 5, 2014
[FIXED JENKINS-24095] Ensure only numExecutors exist when reducing
When reducing the number of executors from M to N, previously it'd kill all idle executors, and then create executors 0...N-1 unless they already exist (busy executors). This can lead to the situation where e.g. executor #5 is busy and retained, and when setting the number of executors to 3, 0...2 are created, resulting temporarily having 4 executors. This change prevents #2 from being created in the example. When #4 is finished, it'll be killed anyway and a new executor #2 created, so after some time the executor indexes are cleaned up matching expectations.
1 parent 551c968 commit 05a26da

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed
 

‎core/src/main/java/hudson/model/Computer.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -721,9 +721,16 @@ private void addNewExecutorIfNecessary() {
721721
availableNumbers.remove(executor.getNumber());
722722

723723
for (Integer number : availableNumbers) {
724-
Executor e = new Executor(this, number);
725-
executors.add(e);
724+
/* There may be busy executors with higher index, so only
725+
fill up until numExecutors is reached.
726+
Extra executors will call removeExecutor(...) and that
727+
will create any necessary executors from #0 again. */
728+
if (executors.size() < numExecutors) {
729+
Executor e = new Executor(this, number);
730+
executors.add(e);
731+
}
726732
}
733+
727734
}
728735

729736
/**

0 commit comments

Comments
 (0)