You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "suez1224 (via GitHub)" <gi...@apache.org> on 2025/01/13 07:28:09 UTC

[PR] [FLINK-37084][python] fix TimerRegistration concurrency bug in pyflink [flink]

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

   <!--
   *Thank you very much for contributing to Apache Flink - we are happy that you want to help us improve Flink. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
   
   *Please understand that we do not do this to make contributions to Flink a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
     
     - Name the pull request in the form "[FLINK-XXXX] [component] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number. Skip *component* if you are unsure about which is the best component.
     Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix] [docs] Fix typo in event time introduction` or `[hotfix] [javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes. You can set up Azure Pipelines CI to do that following [this guide](https://cwiki.apache.org/confluence/display/FLINK/Azure+Pipelines#AzurePipelines-Tutorial:SettingupAzurePipelinesforaforkoftheFlinkrepository).
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message (including the JIRA id)
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   ## What is the purpose of the change
   
   There is a concurrent bug in pyflink between timer registration (which happens in TimerRegistration.setTimer) and timer processing (InternalTimerServiceImpl.onProcessingTime). Currently the timer registration of Python operator isn't handled in the main thread. This PR fix the concurrency problem in pyflink.
   
   
   ## Brief change log
   
     - *Move Timer registration in pyflink from gRPC thread to main thread*
   
   
   ## Verifying this change
   
   Please make sure both new and modified tests in this PR follow [the conventions for tests defined in our code quality guide](https://flink.apache.org/how-to-contribute/code-style-and-quality-common/#7-testing).
   
   
   This change added tests and can be verified as follows:
   
     - Manually verified the change by running a pyflink job that frequently triggered the concurrency bug. After the fix, the job are able to run for >24 hours w/o the issue.
   
   ## 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: (no)
     - The runtime per-record code paths (performance sensitive): (no)
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (no)
     - The S3 file system connector: (no)
   
   ## 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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37084][python] fix TimerRegistration concurrency bug in pyflink [flink]

Posted by "dianfu (via GitHub)" <gi...@apache.org>.
dianfu commented on code in PR #25965:
URL: https://github.com/apache/flink/pull/25965#discussion_r1913049536


##########
flink-python/src/main/java/org/apache/flink/streaming/api/runners/python/beam/BeamPythonFunctionRunner.java:
##########
@@ -681,7 +686,14 @@ public void onCompleted(BeamFnApi.ProcessBundleResponse response) {
 
     private TimerReceiverFactory createTimerReceiverFactory() {
         BiConsumer<Timer<?>, TimerInternals.TimerData> timerDataConsumer =
-                (timer, timerData) -> timerRegistration.setTimer((byte[]) timer.getUserKey());
+                (timer, timerData) ->
+                        environment
+                                .getMainMailboxExecutor()

Review Comment:
   `environment.getMainMailboxExecutor()` has a side effect that it will create MainMailboxExecutor instance each time called. What about making MainMailboxExecutor an instance variable?



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37084][python] fix TimerRegistration concurrency bug in pyflink [flink]

Posted by "suez1224 (via GitHub)" <gi...@apache.org>.
suez1224 commented on PR #25965:
URL: https://github.com/apache/flink/pull/25965#issuecomment-2597571178

   @flinkbot run azure


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37084][python] fix TimerRegistration concurrency bug in pyflink [flink]

Posted by "suez1224 (via GitHub)" <gi...@apache.org>.
suez1224 closed pull request #25965: [FLINK-37084][python] fix TimerRegistration concurrency bug in pyflink
URL: https://github.com/apache/flink/pull/25965


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37084][python] fix TimerRegistration concurrency bug in pyflink [flink]

Posted by "suez1224 (via GitHub)" <gi...@apache.org>.
suez1224 commented on code in PR #25965:
URL: https://github.com/apache/flink/pull/25965#discussion_r1914308321


##########
flink-python/src/main/java/org/apache/flink/streaming/api/runners/python/beam/BeamPythonFunctionRunner.java:
##########
@@ -681,7 +686,14 @@ public void onCompleted(BeamFnApi.ProcessBundleResponse response) {
 
     private TimerReceiverFactory createTimerReceiverFactory() {
         BiConsumer<Timer<?>, TimerInternals.TimerData> timerDataConsumer =
-                (timer, timerData) -> timerRegistration.setTimer((byte[]) timer.getUserKey());
+                (timer, timerData) ->
+                        environment
+                                .getMainMailboxExecutor()

Review Comment:
   I believe the mainMailboxExecutor is set once for the StreamTask here https://github.com/apache/flink/blob/60497e7dfddf27b25b80b913ef259010e97569aa/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/tasks/StreamTask.java#L458. And when Environment.getMainMainboxExecutor() is called here https://github.com/apache/flink/blob/60497e7dfddf27b25b80b913ef259010e97569aa/flink-runtime/src/main/java/org/apache/flink/runtime/taskmanager/RuntimeEnvironment.java#L376, it only returns the instance variable directly. I did not see any side effect in the code, or do I miss anything? Thanks



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37084][python] fix TimerRegistration concurrency bug in pyflink [flink]

Posted by "suez1224 (via GitHub)" <gi...@apache.org>.
suez1224 commented on PR #25965:
URL: https://github.com/apache/flink/pull/25965#issuecomment-2597710037

   created https://github.com/apache/flink/pull/26004 to trigger CI test.


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37084][python] fix TimerRegistration concurrency bug in pyflink [flink]

Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #25965:
URL: https://github.com/apache/flink/pull/25965#issuecomment-2586398302

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "74e3604497a6d7b2f775e1d4b36b98f1efa1be0a",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "74e3604497a6d7b2f775e1d4b36b98f1efa1be0a",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 74e3604497a6d7b2f775e1d4b36b98f1efa1be0a UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run azure` re-run the last Azure build
   </details>


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37084][python] fix TimerRegistration concurrency bug in pyflink [flink]

Posted by "suez1224 (via GitHub)" <gi...@apache.org>.
suez1224 commented on PR #25965:
URL: https://github.com/apache/flink/pull/25965#issuecomment-2589130902

   I believe the mainMailboxExecutor is set once for the StreamTask here https://github.com/apache/flink/blob/60497e7dfddf27b25b80b913ef259010e97569aa/flink-runtime/src/main/java/org/apache/flink/streaming/runtime/tasks/StreamTask.java#L458. And when Environment.getMainMainboxExecutor() is called here https://github.com/apache/flink/blob/60497e7dfddf27b25b80b913ef259010e97569aa/flink-runtime/src/main/java/org/apache/flink/runtime/taskmanager/RuntimeEnvironment.java#L376, it only returns the instance variable directly. I did not see any side effect in the code, or do I miss anything? Thanks


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37084][python] fix TimerRegistration concurrency bug in pyflink [flink]

Posted by "dianfu (via GitHub)" <gi...@apache.org>.
dianfu commented on PR #25965:
URL: https://github.com/apache/flink/pull/25965#issuecomment-2589294392

   @suez1224 You are right. There are some test failures which seems related to this PR. Could you take a look?


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37084][python] fix TimerRegistration concurrency bug in pyflink [flink]

Posted by "suez1224 (via GitHub)" <gi...@apache.org>.
suez1224 commented on PR #25965:
URL: https://github.com/apache/flink/pull/25965#issuecomment-2597601633

   @flinkbot run azure


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org