mjsax commented on a change in pull request #8900: URL: https://github.com/apache/kafka/pull/8900#discussion_r444518329
########## File path: streams/src/main/java/org/apache/kafka/streams/processor/internals/TaskManager.java ########## @@ -679,92 +675,166 @@ private void cleanupTask(final Task task) { void shutdown(final boolean clean) { final AtomicReference<RuntimeException> firstException = new AtomicReference<>(null); - final Set<Task> tasksToClose = new HashSet<>(); + final Set<Task> tasksToCloseDirty = new HashSet<>(); + tasksToCloseDirty.addAll(tryCloseCleanAllActiveTasks(clean, firstException)); + tasksToCloseDirty.addAll(tryCloseCleanAllStandbyTasks(clean, firstException)); + + for (final Task task : tasksToCloseDirty) { + closeTaskDirty(task); + } + + for (final Task task : activeTaskIterable()) { + executeAndMaybeSwallow( + clean, + () -> activeTaskCreator.closeAndRemoveTaskProducerIfNeeded(task.id()), + e -> firstException.compareAndSet(null, e), + e -> log.warn("Ignoring an exception while closing task " + task.id() + " producer.", e) + ); + } + + executeAndMaybeSwallow( + clean, + activeTaskCreator::closeThreadProducerIfNeeded, + e -> firstException.compareAndSet(null, e), + e -> log.warn("Ignoring an exception while closing thread producer.", e) + ); + + tasks.clear(); + + + // this should be called after closing all tasks, to make sure we unlock the task dir for tasks that may + // have still been in CREATED at the time of shutdown, since Task#close will not do so + executeAndMaybeSwallow( + clean, Review comment: As above. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org