Skip to content

Commit

Permalink
[JENKINS-13564] make the method self-correcting
Browse files Browse the repository at this point in the history
If for some reason the numExecutors field gets out of sync with executors.size() (for example this can happen if an executor swallowed an interrupt signal without properly processing it), then a further attempt to call setNumExecutors(n) results in a no-op.

Given that these things can get out of sync, a smarter thing to do is to always compare where we are (the "executors" variable) and where we'd like to be (numExecutors), and make corrective actions.

This particularly affects a zombie computer. The sequence to kill a Computer first involves waiting for all the executors to quit. If setNumExecutors(0) becomes no-op, a zombine computer never gets killed.
  • Loading branch information
kohsuke committed Mar 28, 2013
1 parent 18f394c commit c3a1967
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions core/src/main/java/hudson/model/Computer.java
Expand Up @@ -691,17 +691,18 @@ protected void onRemoved(){
}

private synchronized void setNumExecutors(int n) {
if(numExecutors==n) return; // no-op

int diff = n-numExecutors;
this.numExecutors = n;
int diff = executors.size()-n;

if(diff<0) {
if (diff>0) {
// we have too many executors
// send signal to all idle executors to potentially kill them off
for( Executor e : executors )
if(e.isIdle())
e.interrupt();
} else {
}

if (diff<0) {
// if the number is increased, add new ones
addNewExecutorIfNecessary();
}
Expand Down

0 comments on commit c3a1967

Please sign in to comment.