Skip to content

Commit

Permalink
Ensure cleanups succeed in JoinValidationService (#90601) (#91253)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
DaveCTurner committed Nov 2, 2022
1 parent 4ff8d7f commit 6bc5f51
Showing 1 changed file with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,27 +229,39 @@ private void processNextItem() {
try {
nextItem.run();
} finally {
final var remaining = queueSize.decrementAndGet();
assert remaining >= 0;
if (remaining > 0) {
runProcessor();
try {
final var remaining = queueSize.decrementAndGet();
assert remaining >= 0;
if (remaining > 0) {
runProcessor();
}
} catch (Exception e) {
assert false : e;
/* we only catch so we can assert false, so throwing is ok */
// noinspection ThrowFromFinallyBlock
throw e;
}
}
}

private void onShutdown() {
// shutting down when enqueueing the next processor run which means there is no active processor so it's safe to clear out the
// cache ...
cacheClearer.run();

// ... and drain the queue
do {
final var nextItem = queue.poll();
assert nextItem != null;
if (nextItem != cacheClearer) {
nextItem.onFailure(new NodeClosedException(transportService.getLocalNode()));
}
} while (queueSize.decrementAndGet() > 0);
try {
// shutting down when enqueueing the next processor run which means there is no active processor so it's safe to clear out the
// cache ...
cacheClearer.run();

// ... and drain the queue
do {
final var nextItem = queue.poll();
assert nextItem != null;
if (nextItem != cacheClearer) {
nextItem.onFailure(new NodeClosedException(transportService.getLocalNode()));
}
} while (queueSize.decrementAndGet() > 0);
} catch (Exception e) {
assert false : e;
throw e;
}
}

private final AbstractRunnable cacheClearer = new AbstractRunnable() {
Expand Down

0 comments on commit 6bc5f51

Please sign in to comment.