Skip to content

Commit bfff8a7

Browse files
committed
fix the validator for anyOf
1 parent 6315574 commit bfff8a7

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

sdk/src/main/java/software/amazon/lambda/durable/execution/ExecutionManager.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
import java.util.concurrent.CancellationException;
1515
import java.util.concurrent.CompletableFuture;
1616
import java.util.concurrent.ThreadPoolExecutor;
17-
import java.util.concurrent.TimeUnit;
18-
import java.util.concurrent.TimeoutException;
1917
import java.util.concurrent.atomic.AtomicReference;
2018
import java.util.stream.Collectors;
2119
import org.slf4j.Logger;
@@ -282,35 +280,38 @@ public CompletableFuture<Operation> pollForOperationUpdates(String operationId,
282280
/** Shutdown the checkpoint batcher. */
283281
@Override
284282
public void close() {
285-
checkpointManager.shutdown();
286-
287283
validateRunningThreads();
284+
285+
checkpointManager.shutdown();
288286
}
289287

290288
private void validateRunningThreads() {
291289
// This will detect stuck user thread and thread leaks in the thread pool
292290
for (BaseDurableOperation op : registeredOperations.values()) {
293291
var userHandlerFuture = op.getRunningUserHandler();
294292
if (userHandlerFuture != null && !userHandlerFuture.isDone()) {
295-
// We wait a few more milliseconds for the last user thread to complete because
296-
// it may have deregistered itself but haven't released the thread yet.
293+
// Some user threads can still be running because
294+
// the operations that run them have never been waiting for and the execution has completed.
297295
logger.info("Waiting for operation to complete before shutting down: {}", op.getOperationId());
298296
try {
299297
userHandlerFuture.get();
300298
} catch (InterruptedException | CancellationException e) {
301299
// if the user handler is stuck
302-
throw new IllegalStateException("Stuck running user handler when shutting down: " + op.getOperationId());
300+
throw new IllegalStateException(
301+
"Stuck running user handler when shutting down: " + op.getOperationId());
303302
} catch (Exception e) {
304303
// ok if the future completed exceptionally
305304
}
306305
}
307306
}
308307

308+
// double check if the thread pool is empty
309309
if (durableConfig.getExecutorService() instanceof ThreadPoolExecutor threadPoolExecutor) {
310310
var threadCount = threadPoolExecutor.getActiveCount();
311311
if (threadCount > 0) {
312-
// this may or may not be a problem because getActiveCount doesn't return an accurate number
313312
logger.warn("{} active threads in user executor pool when shutting down", threadCount);
313+
throw new IllegalStateException(
314+
"Threads still running on user executor pool when shutting down: " + threadCount);
314315
}
315316
}
316317
}

0 commit comments

Comments
 (0)