Skip to content

Commit

Permalink
Check if threadpool exists in this.observers before trying to access
Browse files Browse the repository at this point in the history
  • Loading branch information
gareth-ellis committed Oct 16, 2023
1 parent cd705dd commit e0c55f2
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions server/src/main/java/org/elasticsearch/threadpool/ThreadPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -621,13 +621,15 @@ public void shutdown() {
scheduler.shutdown();
for (ExecutorHolder executor : executors.values()) {
if (executor.executor() instanceof ThreadPoolExecutor) {
this.observers.get(executor.info.getName()).forEach((k, v) -> {
try {
v.close();
} catch (Exception e) {
logger.warn(format("Failed to close LongGaugeObserver for %s. %s", executor.info.getName(), e.getMessage()));
}
});
if (this.observers.containsKey(executor.info.getName())) {
this.observers.get(executor.info.getName()).forEach((k, v) -> {
try {
v.close();
} catch (Exception e) {
logger.warn(format("Failed to close LongGaugeObserver for %s. %s", executor.info.getName(), e.getMessage()));
}
});
}
this.observers.remove(executor.info.getName());
executor.executor().shutdown();
}
Expand All @@ -639,13 +641,15 @@ public void shutdownNow() {
scheduler.shutdownNow();
for (ExecutorHolder executor : executors.values()) {
if (executor.executor() instanceof ThreadPoolExecutor) {
this.observers.get(executor.info.getName()).forEach((k, v) -> {
try {
v.close();
} catch (Exception e) {
logger.warn(format("Failed to close LongGaugeObserver for %s. %s", executor.info.getName(), e.getMessage()));
}
});
if (this.observers.containsKey(executor.info.getName())) {
this.observers.get(executor.info.getName()).forEach((k, v) -> {
try {
v.close();
} catch (Exception e) {
logger.warn(format("Failed to close LongGaugeObserver for %s. %s", executor.info.getName(), e.getMessage()));
}
});
}
executor.executor().shutdownNow();
}
}
Expand All @@ -655,13 +659,15 @@ public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedE
boolean result = scheduler.awaitTermination(timeout, unit);
for (ExecutorHolder executor : executors.values()) {
if (executor.executor() instanceof ThreadPoolExecutor) {
this.observers.get(executor.info.getName()).forEach((k, v) -> {
try {
v.close();
} catch (Exception e) {
logger.warn(format("Failed to close LongGaugeObserver for %s. %s", executor.info.getName(), e.getMessage()));
}
});
if (this.observers.containsKey(executor.info.getName())) {
this.observers.get(executor.info.getName()).forEach((k, v) -> {
try {
v.close();
} catch (Exception e) {
logger.warn(format("Failed to close LongGaugeObserver for %s. %s", executor.info.getName(), e.getMessage()));
}
});
}
result &= executor.executor().awaitTermination(timeout, unit);
}
}
Expand Down

0 comments on commit e0c55f2

Please sign in to comment.