sunm2n commented on PR #23549:
URL: https://github.com/apache/kafka/pull/23549#issuecomment-6784250529

   Thanks @lucasbru, agreed, and I confirmed both before changing anything. 
With the flag set, the removal waits that are still pending fail immediately, 
so the tasks the updater still owns are closed dirty and lose their restore 
progress. With the streams protocol, `addStreamThread` on the dying thread 
fails in `ConsumerNetworkThread.start` on `initializationLatch.await()`; 
`SHUTDOWN_APPLICATION` with a single live thread goes through the same path.
   
   Pushed the change to `StreamThread.run()` as you sketched it in 81baaf8261: 
the flag is cleared and recorded in the `catch` before the handler runs, 
cleared once more in the `finally` before `completeShutdown`, and restored in 
an inner `finally` so it survives an exception from the shutdown. The 
`TaskManager` changes stay for an interrupt that arrives while the thread is 
already shutting down.
   
   Four unit tests in `StreamThreadTest`: the flag is cleared during shutdown 
and restored afterwards, cleared before the uncaught exception handler runs, 
cleared during shutdown even when the handler itself set it, and restored when 
`completeShutdown` throws. The first three fail without the change; the fourth 
fails if the inner `finally` is removed.
   
   I also ran it against a real broker with one stream thread:
   
   - Interrupted while restoring, `REPLACE_THREAD` and `SHUTDOWN_APPLICATION` 
with the streams protocol now work; before, the client was left with no stream 
thread.
   - Restore progress is kept: after an interrupt at offset 1999, the restart 
resumes from 2000 instead of 0.
   - Two user-visible differences: the uncaught exception handler and the state 
listener (`RUNNING` → `PENDING_ERROR`) now run with the flag cleared, and the 
shutdown can take longer because the consumer close is no longer cut short by 
the interrupt. In my runs, a thread interrupted during processing took about 
500 ms longer to reach `DEAD`, while the shutdown time for a thread interrupted 
during restore did not change noticeably.
   
   Not covered here: `GlobalStreamThread` has its own `run()`, which calls the 
uncaught exception handler and closes its state consumer in the `finally` with 
the flag still set. With a user handler that returns `SHUTDOWN_APPLICATION` and 
a single stream thread, `addStreamThread` then runs on the interrupted global 
thread. Happy to file a follow-up if you think it should get the same treatment.
   


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