raulpardo opened a new pull request, #26219:
URL: https://github.com/apache/flink/pull/26219

   ## What is the purpose of the change
   
   This is a hotfix fixing a data race in `drain()` method in 
`TaskMailboxImpl.java`. This can lead to undesired executions. For instance, 
consider the that mailbox thread is adding a `mail` by executing `putFirst`, 
and concurrently another thread is executing `drain()`. This can produce the 
following execution: 
   1. The read of `batch` 
[here](https://github.com/apache/flink/blob/34a7734c489b080d34ff2194a29d3c1d25d3ab45/flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/tasks/mailbox/TaskMailboxImpl.java#L246)
 is executed before `addFirst(mail)` ([in this 
line](https://github.com/apache/flink/blob/34a7734c489b080d34ff2194a29d3c1d25d3ab45/flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/tasks/mailbox/TaskMailboxImpl.java#L210C13-L210C18))
 adds the element, 
   2. Then, `mail` is added to `batch` (consequentely, `mail` is not in 
`drainedMails`) 
   3. Finally, `batch.clear()` is executed. 
    
   This execution results in missing `mail` (as it is neither included in 
`batch` nor `drainedMails`).
   
   This hotfix PR resolves the data race by including the read to `batch` and 
its clearing within the critical section in the `drain()` method.
   
   ## Brief change log
   
   - Reading and clearing variable `batch` in the method `drain()` in 
`TaskMailboxImpl.java` are moved into the critical section within the method.
   
   
   ## Verifying this change
   
   
   This change is a trivial rework / code cleanup without any test coverage.
   
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): no
     - The public API, i.e., is any changed class annotated with 
`@Public(Evolving)`: no
     - The serializers: don't know
     - The runtime per-record code paths (performance sensitive): don't know
     - Anything that affects deployment or recovery: JobManager (and its 
components), Checkpointing, Kubernetes/Yarn, ZooKeeper: don't know
     - The S3 file system connector: don't know
   
   ## Documentation
   
     - Does this pull request introduce a new feature? no
     - If yes, how is the feature documented? not applicable
   


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