Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue #787 for cannot close and exit properly when rebalancing storm #789

Merged
merged 4 commits into from
Jun 6, 2024
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ endif::[]

=== Fixes

* fix: fix issue for cannot close and exit properly when re-balancing storm (#787)
* fix: Support for PCRetriableException in ReactorProcessor (#733)
* fix: NullPointerException on partitions revoked (#757)
* fix: remove lingeringOnCommitWouldBeBeneficial and unused imports (#732)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ public static <K, V> ControllerEventMessage<K, V> of(WorkContainer<K, V> work) {
*/
private final AtomicBoolean currentlyPollingWorkCompleteMailBox = new AtomicBoolean();

/**
* Indicates state of waiting while in-flight messages complete processing on shutdown.
* Used to prevent control thread interrupt due to wakeup logic on rebalances
*/
private final AtomicBoolean awaitingInflightProcessingCompletionOnShutdown = new AtomicBoolean();

private final OffsetCommitter committer;

/**
Expand Down Expand Up @@ -639,6 +645,7 @@ private void doClose(Duration timeout) throws TimeoutException, ExecutionExcepti
}

log.debug("Awaiting worker pool termination...");
awaitingInflightProcessingCompletionOnShutdown.getAndSet(true);
boolean awaitingInflightCompletion = true;
while (awaitingInflightCompletion) {
log.debug("Still awaiting completion of inflight work");
Expand All @@ -657,6 +664,8 @@ private void doClose(Duration timeout) throws TimeoutException, ExecutionExcepti
awaitingInflightCompletion = true;
}
}
awaitingInflightProcessingCompletionOnShutdown.getAndSet(false);

if (workerThreadPool.get().getActiveCount() > 0) {
log.warn("Clean execution pool termination failed - some threads still active despite await and interrupt - is user function swallowing interrupted exception? Threads still not done count: {}", workerThreadPool.get().getActiveCount());
}
Expand Down Expand Up @@ -1401,7 +1410,8 @@ public void registerWork(EpochAndRecordsMap<K, V> polledRecords) {
*/
public void notifySomethingToDo() {
boolean noTransactionInProgress = !producerManager.map(ProducerManager::isTransactionCommittingInProgress).orElse(false);
if (noTransactionInProgress) {
// do not interrupt while workerThreadPool is draining submitted / inflight tasks
if (noTransactionInProgress && !awaitingInflightProcessingCompletionOnShutdown.get()) {
log.trace("Interrupting control thread: Knock knock, wake up! You've got mail (tm)!");
interruptControlThread();
} else {
Expand Down