awslabs / amazon-kinesis-client

Client library for Amazon Kinesis
Apache License 2.0
635 stars 461 forks source link

Correcting the behavior of gracefulShutdown #1302

Closed vincentvilo-aws closed 3 months ago

vincentvilo-aws commented 3 months ago

Issue #, if available: #616

Description of changes: This PR corrects the behavior of Scheduler's gracefulShutdown.

Originally, calling Scheduler.startGracefulShutdown() would return false because the CountDownLatch used to track the shutdowns of the record processors was never decremented. To address this issue, the CountDownLatch is decremented within the ConsumerTask of the ShuttingDownState (see ShutdownTask.java). The ShutdownCompleteState is now used as a terminal state and contains no associated ConsumerTask.

Also, another CountDownLatch was introduced to the Scheduler to ensure that its finalShutdown()method is returned before the startGracefulShutdown() returns.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.