From bcfc3253645a22848c2e06cc975f3c5e84857f28 Mon Sep 17 00:00:00 2001 From: "Pfifer, Justin" Date: Tue, 14 Feb 2017 09:52:00 -0800 Subject: [PATCH] Add some more comments around possible race conditions. --- .../kinesis/clientlibrary/lib/worker/Worker.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/amazonaws/services/kinesis/clientlibrary/lib/worker/Worker.java b/src/main/java/com/amazonaws/services/kinesis/clientlibrary/lib/worker/Worker.java index ec876f2d..7ebfc3f3 100644 --- a/src/main/java/com/amazonaws/services/kinesis/clientlibrary/lib/worker/Worker.java +++ b/src/main/java/com/amazonaws/services/kinesis/clientlibrary/lib/worker/Worker.java @@ -538,10 +538,12 @@ public class Worker implements Runnable { */ public Future requestShutdown() { + // + // Stop accepting new leases. Once we do this we can be sure that + // no more leases will be acquired. + // leaseCoordinator.stopLeaseTaker(); - // - // Stop accepting new leases - // + Collection leases = leaseCoordinator.getAssignments(); if (leases == null || leases.isEmpty()) { // @@ -560,6 +562,11 @@ public class Worker implements Runnable { if (consumer != null) { consumer.notifyShutdownRequested(shutdownNotification); } else { + // + // There is a race condition between retrieving the current assignments, and creating the + // notification. If the a lease is lost in between these two points, we explicitly decrement the + // notification latches to clear the shutdown. + // notificationCompleteLatch.countDown(); shutdownCompleteLatch.countDown(); }