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

   ## Problem
   
   `AsyncKafkaConsumer.close()` keeps shutting down after an interrupt and then 
rethrows the saved `InterruptException`. While it waits for the network thread, 
`ConsumerNetworkThread.closeInternal` calls `Thread.join()`. `join()` clears 
the interrupt status when it throws, and that catch only logged the error. 
After `close()` threw, `Thread.interrupted()` was false.
   
   ## Fix
   
   Restore the interrupt status in the `join()` catch. `close()` still rethrows 
the saved `InterruptException` and does not set the flag itself.
   
   This is not the approach in the closed, unmerged #21864. That PR called 
`Thread.currentThread().interrupt()` immediately before the rethrow in the 
async consumer, classic consumer, share consumer, and producer. The concern 
there was that restoring the flag only at the throw hides whichever cleanup 
step cleared it. This change restores it at the `join()` that clears it. The 
classic consumer and the producer do not use this `join()`, so they are 
unchanged. The share consumer uses the same network thread, so it is covered 
without a second `interrupt()` on its throw.
   
   ## Tests
   
   `ConsumerNetworkThreadTest.testCloseRestoresInterruptStatusClearedByJoin` 
starts a network thread that stays alive, interrupts the caller, and calls 
`close()`, so `join()` actually waits. The flag was clear before the restore 
and is still set after it.
   
   This work is original and licensed to the project under the Apache License 
2.0.


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