[ 
https://issues.apache.org/jira/browse/KAFKA-15205?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17744377#comment-17744377
 ] 

Ismael Juma commented on KAFKA-15205:
-------------------------------------

Have you seen this behavior in practice? We should definitely fix our error 
handling if it's not compliant, but it's not clear to me if this is more of a 
theoretical issue.

> Race condition in ShutdownableThread causes InterruptedException
> ----------------------------------------------------------------
>
>                 Key: KAFKA-15205
>                 URL: https://issues.apache.org/jira/browse/KAFKA-15205
>             Project: Kafka
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.3.2, 3.4.1, 3.6.0, 3.5.1
>            Reporter: Divij Vaidya
>            Priority: Major
>             Fix For: 3.6.0
>
>
> In Shutdownable thread, during close, we call:
> initiateShutdown() -> which may interrupt the thread if 
> isInterruptible is set to true during construction.
> After that, we wait for proper shutdown using 
> awaitShutdown() which in-turn calls CountdownLatch#await(). On interruption, 
> which could be caused by initiateShutdown() earlier, await() throws an 
> InterruptedExeception. Hence, awaitShutdown() is going to exit by throwing an 
> interrupted exception.
> The sequence to reproduce this will be as follows:
> App-thread: Name of application thread which spawns and closes Shutdownable 
> thread
> Shut-thread: Name of the shutdownable thread.
> 1. App-thread calls ShutThread.initiateShutdown()
> 2. ShutThread.interrupt() is called. It informs the VM to interrupt but the 
> actual interrupt will be async. initiateShutdown() from step 1 returns.
> 3. App-thread calls ShutThread.awaitShutdown() 
> 4. App-thread waits on shutdownComplete.await() i.e. on CountdownLatch#await
> 5. VM decides to interrupt App-thread and there is a race condition now.
> Race condition:
> Condition 1: Shut-thread.doWork() gets interrupted exception, and decrements 
> the CountdownLatch
> Condition 2: App-thread waiting on Shut-thread.shutdownComplete.await() 
> throws an interruptedException as per the contract 
> [https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CountDownLatch.html#await--]
> *Solution*
>  
> In ShutDownableThread#awaitShutdown(), when calling await() we should catch 
> InterruptedException and eat it up (do nothing), if the thread has 
> isInterruptable set to true.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to