Skip to content

Commit

Permalink
Call listener synchronously, but outside synchronized
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlatombe committed Aug 28, 2024
1 parent 9823b8e commit 75242cf
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions core/src/main/java/hudson/model/Computer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,7 @@ public final long getDemandStartMilliseconds() {
*/
protected void removeExecutor(final Executor e) {
final Runnable task = () -> {
var idle = false;
synchronized (Computer.this) {
executors.remove(e);
oneOffExecutors.remove(e);
Expand All @@ -1104,10 +1105,13 @@ protected void removeExecutor(final Executor e) {
if (ciBase != null) { // TODO confirm safe to assume non-null and use getInstance()
ciBase.removeComputer(Computer.this);
}
} else if (isIdle()) {
threadPoolForRemoting.submit(() -> Listeners.notify(ComputerListener.class, false, l -> l.onIdle(this)));
} else {
idle = isIdle();
}
}
if (idle) {
Listeners.notify(ComputerListener.class, false, l -> l.onIdle(this));
}
};
if (!Queue.tryWithLock(task)) {
// JENKINS-28840 if we couldn't get the lock push the operation to a separate thread to avoid deadlocks
Expand Down

0 comments on commit 75242cf

Please sign in to comment.