You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "arunpandianp (via GitHub)" <gi...@apache.org> on 2025/12/13 02:22:36 UTC
[PR] [Dataflow Streaming] Fix race in StreamingEngineWorkComitter during stream shutdown [beam]
arunpandianp opened a new pull request, #37104:
URL: https://github.com/apache/beam/pull/37104
The race is between commit() and stop().
Since it happens only during shutdown, it doesn't affect cloudpath where commiter is not shutdown till the worker shutdown.
directpath is affected since it can shutdown committers all the time.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Dataflow Streaming] Fix race in StreamingEngineWorkComitter during stream shutdown [beam]
Posted by "arunpandianp (via GitHub)" <gi...@apache.org>.
arunpandianp commented on PR #37104:
URL: https://github.com/apache/beam/pull/37104#issuecomment-3648768051
R: @scwhittle @parveensania
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Dataflow Streaming] Fix race in StreamingEngineWorkComitter during stream shutdown [beam]
Posted by "scwhittle (via GitHub)" <gi...@apache.org>.
scwhittle commented on code in PR #37104:
URL: https://github.com/apache/beam/pull/37104#discussion_r2618895796
##########
runners/google-cloud-dataflow-java/worker/src/test/java/org/apache/beam/runners/dataflow/worker/windmill/client/commits/StreamingEngineWorkCommitterTest.java:
##########
@@ -400,4 +415,57 @@ public void testMultipleCommitSendersSingleStream() {
workCommitter.stop();
}
+
+ @Test
+ public void testStop_drainsCommitQueue_concurrentCommit() throws InterruptedException {
+ Set<CompleteCommit> completeCommits = Collections.newSetFromMap(new ConcurrentHashMap<>());
+ workCommitter =
+ StreamingEngineWorkCommitter.builder()
+ // Set the semaphore to only allow a single commit at a time.
+ // This creates a bottleneck on purpose to trigger race conditions during shutdown.
+ .setCommitByteSemaphore(WeightedSemaphore.create(1, (commit) -> 1))
+ .setCommitWorkStreamFactory(commitWorkStreamFactory)
+ .setOnCommitComplete(completeCommits::add)
+ .build();
+
+ int numThreads = 5;
+ ExecutorService producer = Executors.newFixedThreadPool(numThreads);
+ AtomicBoolean producing = new AtomicBoolean(true);
+ AtomicLong sentCommits = new AtomicLong(0);
+
+ workCommitter.start();
+
+ AtomicLong workToken = new AtomicLong(0);
+ for (int i = 0; i < numThreads; i++) {
+ @SuppressWarnings("FutureReturnValueIgnored")
+ Future<?> unused =
Review Comment:
instead of ignoring, how about joining all of these at the end of the test? That also verifies these threads don't get stuck somewhere calling commit.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Dataflow Streaming] Fix race in StreamingEngineWorkComitter during stream shutdown [beam]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on PR #37104:
URL: https://github.com/apache/beam/pull/37104#issuecomment-3648768043
## Summary of Changes
Hello @arunpandianp, I'm Gemini Code Assist[^1]! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request resolves a critical race condition within the `StreamingEngineWorkCommitter` that could lead to uncommitted work items during stream shutdown, particularly affecting `directpath` environments. The changes ensure that all commits are properly processed, even when the system is concurrently shutting down, by adjusting the order of operations in the `commit()` method and explicitly draining the commit queue. A new, comprehensive test has been added to validate this fix under concurrent conditions, significantly improving the reliability of the streaming engine's commit mechanism.
### Highlights
* **Race Condition Fix**: Addressed a race condition between the `commit()` and `stop()` methods within the `StreamingEngineWorkCommitter` during stream shutdown, specifically impacting `directpath` executions.
* **Commit Handling during Shutdown**: Modified the `commit()` method to ensure that work items are added to the commit queue before checking if the committer is shutting down. If shutdown is in progress, `drainCommitQueue()` is explicitly called to process any newly added commits, preventing them from being orphaned.
* **New Concurrency Test**: Introduced a new test case, `testStop_drainsCommitQueue_concurrentCommit`, which simulates concurrent `commit()` calls during a shutdown sequence to verify that the commit queue is correctly drained under these conditions.
* **Test Robustness Improvement**: Enhanced the `waitForExpectedSetSize` utility method in the test suite by adding a timeout, making tests more robust against indefinite waits.
<details>
<summary><b>Using Gemini Code Assist</b></summary>
<br>
The full guide for Gemini Code Assist can be found on our [documentation page](https://developers.google.com/gemini-code-assist/docs/review-github-code), here are some quick tips.
<b>Invoking Gemini</b>
You can request assistance from Gemini at any point by creating a comment using either `/gemini <command>` or `@gemini-code-assist <command>`. Below is a summary of the supported commands on the current page.
Feature | Command | Description
--- | --- | ---
Code Review | `/gemini review` | Performs a code review for the current pull request in its current state.
Pull Request Summary | `/gemini summary` | Provides a summary of the current pull request in its current state.
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help | `/gemini help` | Displays a list of available commands.
<b>Customization</b>
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a `.gemini/` folder in the base of the repository. Detailed instructions can be found [here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github).
<b>Limitations & Feedback</b>
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with :thumbsup: and :thumbsdown: on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up [here](https://google.qualtrics.com/jfe/form/SV_2cyuGuTWsEw84yG).
<b>You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the [Gemini Code Assist IDE Extension](https://cloud.google.com/products/gemini/code-assist).</b>
</details>
[^1]: Review the [Privacy Notices](https://policies.google.com/privacy), [Generative AI Prohibited Use Policy](https://policies.google.com/terms/generative-ai/use-policy), [Terms of Service](https://policies.google.com/terms), and learn how to configure Gemini Code Assist in GitHub [here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github). Gemini can make mistakes, so double check it and [use code with caution](https://support.google.com/legal/answer/13505487).
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Dataflow Streaming] Fix race in StreamingEngineWorkComitter during stream shutdown [beam]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #37104:
URL: https://github.com/apache/beam/pull/37104#issuecomment-3648768866
Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment `assign set of reviewers`
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Dataflow Streaming] Fix race in StreamingEngineWorkComitter during stream shutdown [beam]
Posted by "arunpandianp (via GitHub)" <gi...@apache.org>.
arunpandianp commented on code in PR #37104:
URL: https://github.com/apache/beam/pull/37104#discussion_r2621120935
##########
runners/google-cloud-dataflow-java/worker/src/test/java/org/apache/beam/runners/dataflow/worker/windmill/client/commits/StreamingEngineWorkCommitterTest.java:
##########
@@ -400,4 +415,57 @@ public void testMultipleCommitSendersSingleStream() {
workCommitter.stop();
}
+
+ @Test
+ public void testStop_drainsCommitQueue_concurrentCommit() throws InterruptedException {
+ Set<CompleteCommit> completeCommits = Collections.newSetFromMap(new ConcurrentHashMap<>());
+ workCommitter =
+ StreamingEngineWorkCommitter.builder()
+ // Set the semaphore to only allow a single commit at a time.
+ // This creates a bottleneck on purpose to trigger race conditions during shutdown.
+ .setCommitByteSemaphore(WeightedSemaphore.create(1, (commit) -> 1))
+ .setCommitWorkStreamFactory(commitWorkStreamFactory)
+ .setOnCommitComplete(completeCommits::add)
+ .build();
+
+ int numThreads = 5;
+ ExecutorService producer = Executors.newFixedThreadPool(numThreads);
+ AtomicBoolean producing = new AtomicBoolean(true);
+ AtomicLong sentCommits = new AtomicLong(0);
+
+ workCommitter.start();
+
+ AtomicLong workToken = new AtomicLong(0);
+ for (int i = 0; i < numThreads; i++) {
+ @SuppressWarnings("FutureReturnValueIgnored")
+ Future<?> unused =
Review Comment:
done.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Dataflow Streaming] Fix race in StreamingEngineWorkComitter during stream shutdown [beam]
Posted by "scwhittle (via GitHub)" <gi...@apache.org>.
scwhittle merged PR #37104:
URL: https://github.com/apache/beam/pull/37104
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org