Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ public CompletableResultCode shutdown() {

@Override
public CompletableResultCode forceFlush() {
// Once shutdown has flipped the worker's isShutdown the worker thread is on its way out
// (or already exited). A fresh forceFlush would install a flushRequested that nothing is
// left to complete, and callers blocking on the returned result would wait forever.
// Mirror the no-op success behavior already used by the shutdown re-entry guard.
if (worker.isShutdown()) {
return CompletableResultCode.ofSuccess();
}
return worker.forceFlush();
}

Expand Down Expand Up @@ -331,6 +338,10 @@ private CompletableResultCode forceFlush() {
return possibleResult == null ? CompletableResultCode.ofSuccess() : possibleResult;
}

private boolean isShutdown() {
return isShutdown.get();
}

private void exportCurrentBatch() {
if (batch.isEmpty()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,26 @@ void shutdownPropagatesFailure() {
assertThat(result.isSuccess()).isFalse();
}

@Test
void forceFlushAfterShutdownCompletes() {
// forceFlush() invoked after shutdown used to install a flushRequested that no live worker
// could complete, so callers blocking on the returned future would hang until their own
// timeout. The processor should now return an already-successful result instead.
BatchSpanProcessor processor = BatchSpanProcessor.builder(mockSpanExporter).build();

CompletableResultCode shutdown = processor.shutdown();
shutdown.join(5, TimeUnit.SECONDS);
assertThat(shutdown.isDone()).isTrue();

CompletableResultCode flush = processor.forceFlush();
assertThat(flush.isDone())
.withFailMessage(
"forceFlush() after shutdown must return an already-completed result; otherwise"
+ " callers block on a future the dead worker cannot complete")
.isTrue();
assertThat(flush.isSuccess()).isTrue();
}

@Test
void getSpanExporter() {
assertThat(BatchSpanProcessor.builder(mockSpanExporter).build().getSpanExporter())
Expand Down
Loading