Skip to content

[Prism] Fix race condition in element manager#38734

Merged
shunping merged 3 commits into
apache:masterfrom
shunping:fix-refreshcond-race
May 28, 2026
Merged

[Prism] Fix race condition in element manager#38734
shunping merged 3 commits into
apache:masterfrom
shunping:fix-refreshcond-race

Conversation

@shunping
Copy link
Copy Markdown
Collaborator

@shunping shunping commented May 28, 2026

Ensures 'refreshCond.Broadcast()' is fully synchronized with its mutex lock 'refreshCond.L' during pipeline termination and processing-time timer scheduling ('wakeUpAt').

This avoids race conditions causing lost wake-up signals and indefinite test hangs.

Without this change, we have seen a rare deadline exceed on random tests. The goroutine dump suggests that it is stuck in the watermark evaluation loop while the pending element goroutine has ended.

2026-05-28T13:06:16.6677165Z 1 @ 0x48ddee 0x48f833 0x48f813 0x49e9f3 0xc0fc25 0x495621
2026-05-28T13:06:16.6678046Z #  0x48f812        sync.runtime_notifyListWait+0x192                                                                               /usr/local/go/src/runtime/sema.go:617
2026-05-28T13:06:16.6679030Z #  0x49e9f2        sync.(*Cond).Wait+0x72                                                                                          /usr/local/go/src/sync/cond.go:71
2026-05-28T13:06:16.6680753Z #  0xc0fc24        [github.com/apache/beam/sdks/v2/go/pkg/beam/runners/prism/internal/engine.(*ElementManager).Bundles.func2+0x244](https://www.google.com/url?sa=D&q=http%3A%2F%2Fgithub.com%2Fapache%2Fbeam%2Fsdks%2Fv2%2Fgo%2Fpkg%2Fbeam%2Frunners%2Fprism%2Finternal%2Fengine.(*ElementManager).Bundles.func2%2B0x244)  /runner/_work/beam/beam/sdks/go/pkg/beam/runners/prism/internal/engine/elementmanager.go:426
2026-05-28T13:06:16.6682188Z

Example:
https://github.com/apache/beam/actions/runs/26588248130/job/78339963103?pr=38713

shunping added 2 commits May 28, 2026 13:50
Ensures 'refreshCond.Broadcast()' is fully synchronized with
its mutex lock 'refreshCond.L' during pipeline termination and
processing-time timer scheduling ('wakeUpAt').

This avoids race conditions causing lost wake-up signals and
indefinite test hangs.
@shunping shunping marked this pull request as ready for review May 28, 2026 19:16
@shunping
Copy link
Copy Markdown
Collaborator Author

r: @lostluck

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! 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 addresses a race condition in the Prism runner's ElementManager that occasionally caused pipeline termination to hang. By ensuring that condition variable broadcasts are properly synchronized with their associated mutex locks, the change guarantees that wake-up signals are correctly received by the watermark evaluation loop. Additionally, minor adjustments were made to test infrastructure to improve CI stability.

Highlights

  • Race Condition Resolution: Wrapped 'refreshCond.Broadcast()' calls with 'refreshCond.L.Lock()' and 'Unlock()' in the ElementManager to ensure proper synchronization and prevent lost wake-up signals.
  • Test Stability: Updated test configuration files and Gradle tasks to improve reliability and prevent sporadic test hangs in the Prism runner.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

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.

Customization

To customize the 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.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 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.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@shunping shunping requested a review from lostluck May 28, 2026 19:17
@github-actions
Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request triggers a Python post-commit test suite, configures the Prism Java ValidatesRunner task to always run by disabling up-to-date caching, and fixes potential lost wake-up signals in the Go SDK's element manager by locking the mutex before calling Broadcast on refreshCond. A review comment suggests simplifying the Go code by removing an unnecessary outer goroutine wrapper around time.AfterFunc since it is already non-blocking.

Comment thread sdks/go/pkg/beam/runners/prism/internal/engine/elementmanager.go
@shunping
Copy link
Copy Markdown
Collaborator Author

Thanks!

@shunping shunping merged commit a32774a into apache:master May 28, 2026
30 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants