Skip to content

Commit 6bc5f51

Browse files
authored
Ensure cleanups succeed in JoinValidationService (#90601) (#91253)
Today we sort of assume that cleanups succeed in the `JoinValidationService`. A failure in these places might explain the leaks seen in #90576 and #89712. It's not obvious that anything can fail here but let's make sure.
1 parent 4ff8d7f commit 6bc5f51

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

server/src/main/java/org/elasticsearch/cluster/coordination/JoinValidationService.java

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -229,27 +229,39 @@ private void processNextItem() {
229229
try {
230230
nextItem.run();
231231
} finally {
232-
final var remaining = queueSize.decrementAndGet();
233-
assert remaining >= 0;
234-
if (remaining > 0) {
235-
runProcessor();
232+
try {
233+
final var remaining = queueSize.decrementAndGet();
234+
assert remaining >= 0;
235+
if (remaining > 0) {
236+
runProcessor();
237+
}
238+
} catch (Exception e) {
239+
assert false : e;
240+
/* we only catch so we can assert false, so throwing is ok */
241+
// noinspection ThrowFromFinallyBlock
242+
throw e;
236243
}
237244
}
238245
}
239246

240247
private void onShutdown() {
241-
// shutting down when enqueueing the next processor run which means there is no active processor so it's safe to clear out the
242-
// cache ...
243-
cacheClearer.run();
244-
245-
// ... and drain the queue
246-
do {
247-
final var nextItem = queue.poll();
248-
assert nextItem != null;
249-
if (nextItem != cacheClearer) {
250-
nextItem.onFailure(new NodeClosedException(transportService.getLocalNode()));
251-
}
252-
} while (queueSize.decrementAndGet() > 0);
248+
try {
249+
// shutting down when enqueueing the next processor run which means there is no active processor so it's safe to clear out the
250+
// cache ...
251+
cacheClearer.run();
252+
253+
// ... and drain the queue
254+
do {
255+
final var nextItem = queue.poll();
256+
assert nextItem != null;
257+
if (nextItem != cacheClearer) {
258+
nextItem.onFailure(new NodeClosedException(transportService.getLocalNode()));
259+
}
260+
} while (queueSize.decrementAndGet() > 0);
261+
} catch (Exception e) {
262+
assert false : e;
263+
throw e;
264+
}
253265
}
254266

255267
private final AbstractRunnable cacheClearer = new AbstractRunnable() {

0 commit comments

Comments
 (0)