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

Ao Li commented on KAFKA-17929:
-------------------------------

Yes, this issue exists across all Java versions. Apologies for referencing an 
outdated document


https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/Object.html#wait()

OpenJDK has recommended the following solution.


{code:java}
API Note:
The recommended approach to waiting is to check the condition being awaited in 
a while loop around the call to wait, as shown in the example below. Among 
other things, this approach avoids problems that can be caused by spurious 
wakeups.

     synchronized (obj) {
         while (<condition does not hold> and <timeout not exceeded>) {
             long timeoutMillis = ... ; // recompute timeout values
             int nanos = ... ;
             obj.wait(timeoutMillis, nanos);
         }
         ... // Perform action appropriate to condition or timeout
     }
 

{code}




> `awaitProcessableTasks` is not safe in the presence of spurious wakeups.
> ------------------------------------------------------------------------
>
>                 Key: KAFKA-17929
>                 URL: https://issues.apache.org/jira/browse/KAFKA-17929
>             Project: Kafka
>          Issue Type: Bug
>          Components: streams
>            Reporter: Ao Li
>            Priority: Major
>
> According to JDK, `await` can be unblocked due to spurious wakeups 
> https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/locks/Condition.html
> Currently `DefaultTaskManager::awaitProcessableTasks` does not handle this 
> scenario. Branch https://github.com/aoli-al/kafka/tree/KAFKA-82 shows a 
> failing test because of this 
> Command: ./gradlew :streams:test --tests 
> DefaultTaskManagerTest.shouldBlockOnAwait



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

Reply via email to