Copilot commented on code in PR #24310:
URL: https://github.com/apache/kafka/pull/24310#discussion_r4672253960


##########
streams/test-utils/src/main/java/org/apache/kafka/streams/TopologyTestDriver.java:
##########
@@ -376,8 +376,38 @@ public List<PartitionInfo> partitionsFor(final String 
topic) {
             logContext
         );
 
-        setupGlobalTask(mockWallClockTime, streamsConfig, streamsMetrics, 
cache);
-        setupTask(streamsConfig, streamsMetrics, cache, 
internalTopologyBuilder.topologyConfigs().getTaskConfig());
+        try {
+            setupGlobalTask(mockWallClockTime, streamsConfig, streamsMetrics, 
cache);
+            setupTask(streamsConfig, streamsMetrics, cache, 
internalTopologyBuilder.topologyConfigs().getTaskConfig());
+        } catch (final Throwable e) {
+            // the caller gets no driver to close
+            closeDirty(e);
+            throw e;
+        }
+    }
+
+    private void closeDirty(final Throwable cause) {
+        if (task != null) {
+            closeAndSuppress(task::suspend, cause);
+            closeAndSuppress(task::closeDirty, cause);
+        }
+        if (globalStateManager != null) {
+            closeAndSuppress(globalStateManager::close, cause);
+        }
+        // as close() does, so that no state is left behind, whatever made the 
construction fail
+        closeAndSuppress(stateDirectory::clean, cause);

Review Comment:
   The PR description says failed construction does not clean the state 
directory and that deletion is conditional on exactly-once/corruption. This 
unconditional `StateDirectory.clean()` instead deletes all task directories and 
global state for the application, including under at-least-once and for 
non-corrupted transactional stores. Please update the description to document 
this broader, destructive behavior if it is intentional, or restrict cleanup to 
the stated semantics.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to