Skip to content

Commit 54c1bc6

Browse files
committed
decrement outstanding when execution is rejected
1 parent d4db058 commit 54c1bc6

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

server/src/main/java/org/elasticsearch/threadpool/EsExecutorServiceDecorator.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ public void execute(Runnable command) {
157157
return currentValue + 1;
158158
}
159159
});
160+
boolean executed = false;
160161
try {
161162
delegate.execute(() -> {
162163
try {
@@ -167,11 +168,19 @@ public void execute(Runnable command) {
167168
tryShutdownDelegate();
168169
}
169170
});
171+
executed = true;
170172
} catch (RejectedExecutionException e) {
173+
tryShutdownDelegate();
171174
if (command == WORKER_PROBE) {
172175
return;
173176
}
174177
throw new EsRejectedExecutionException("delegate rejected execution", delegate.isShutdown());
178+
} finally {
179+
if (executed == false) {
180+
// Decrement outstanding
181+
runningTasks.decrementAndGet();
182+
tryShutdownDelegate();
183+
}
175184
}
176185
} catch (Exception e) {
177186
if (wrappedRunnable instanceof AbstractRunnable abstractRunnable) {

0 commit comments

Comments
 (0)