eatmoreduck opened a new pull request, #24311:
URL: https://github.com/apache/kafka/pull/24311

   Fixes KAFKA-21580.
   
   ## Description
   
   `TopologyTestDriver`'s core constructor opens the state stores of its global 
and stream tasks (`setupGlobalTask` / `setupTask`). When that setup throws, the 
constructor propagated the failure without closing what it had opened, and the 
caller never receives a driver object, so it cannot call `close()` either. The 
stores stay open until the JVM exits — for a persistent store, the RocksDB 
instance keeps its `LOCK` file held. Failure triggers include a store failing 
to initialize (including `TaskCorruptedException` handling under exactly-once) 
or a processor topology problem surfacing during task initialization.
   
   **Fix**: the constructor wraps the two setup calls in a try-catch; on any 
`Throwable` it runs `close()` before rethrowing. `close()` is null-safe for 
both `task` and `globalStateTask`, and everything it touches beyond them 
(`producer`, `consumer`, `stateDirectory`) is assigned before the failing setup 
runs, so the cleanup cannot NPE on the partially-constructed instance. The 
`this-escape` warning from calling an overridable method in the constructor is 
suppressed with the same annotation used elsewhere in `streams`.
   
   ## Test coverage
   
   `shouldCloseStateStoresWhenConstructorFails` runs against all three 
processing-guarantee subclasses (`TopologyTestDriverTest` at-least-once, 
`TopologyTestDriverEosTest`, and the aligned-subclass matrix): a witness store 
records that its `init` ran before a second store's initializer throws, and 
asserts the witness's `close` ran when the constructor failed. The test fails 
on trunk in the EOS subclasses (the store stays open) and passes with the fix. 
Mutation-checked: removing the try-catch makes the new test fail in all 
affected subclasses.
   


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