Skip to content

Commit

Permalink
Rotate the order of when the shutdown reason is set.
Browse files Browse the repository at this point in the history
Make that happen first, followed by the future to signal wen its done, then followed by teardown.  If the read loop didn't throw to exit, but rather came out because of the boolean check on stopReadingRef, the shutdownReasonRef could still be null by the time that setupRunAndWaitForReplayWithShutdownChecks() checked for it.  Now, that reason will be set before any other code will be impacted by the shutdown, making for more reliable throws when a shutdown due to an error caused the code to exit prematurely.

Signed-off-by: Greg Schohn <greg.schohn@gmail.com>
  • Loading branch information
gregschohn committed Nov 11, 2023
1 parent 54f92de commit 64b3270
Showing 1 changed file with 1 addition and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -870,12 +870,6 @@ private static String formatWorkItem(DiagnosticTrackableCompletableFuture<String
}
}

public void stopReadingAsync() {
log.warn("TrafficReplayer is being signalled to stop reading new TrafficStream objects");
stopReadingRef.set(true);
Optional.ofNullable(this.nextChunkFutureRef.get()).ifPresent(f->f.cancel(true));
}

public @NonNull CompletableFuture<Void> shutdown(Error error) {
log.warn("Shutting down "+this+" because of "+error);
if (!shutdownFutureRef.compareAndSet(null, new CompletableFuture<>())) {
Expand All @@ -886,8 +880,8 @@ public void stopReadingAsync() {
.log();
return shutdownFutureRef.get();
}
stopReadingAsync();
shutdownReasonRef.compareAndSet(null, error);
stopReadingRef.set(true);
nettyShutdownFuture = clientConnectionPool.shutdownNow()
.addListener(f->{
if (f.isSuccess()) {
Expand Down

0 comments on commit 64b3270

Please sign in to comment.