logpuller: fix potential shutdown hang in paused region event push#5610
logpuller: fix potential shutdown hang in paused region event push#5610lidezhu wants to merge 3 commits into
Conversation
|
Skipping CI for Draft Pull Request. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
📝 WalkthroughWalkthroughregionEventSink is updated to track a stopped state alongside paused, with a new stop() helper that broadcasts on the condition variable to release blocked Push callers during shutdown. The constructor no longer stores context; Run and Close invoke stop() accordingly. Tests and call sites are updated to match. ChangesregionEventSink shutdown coordination
Estimated code review effort: 3 (Moderate) | ~25 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request refactors the synchronization mechanism in regionEventSink from using sync.Cond to channel-based coordination (resumeCh and stopCh) to manage pause and resume feedback. It also adds a new test to verify that context cancellation unblocks the Push method. The review feedback suggests optimizing the Push method by keeping the fast path extremely lightweight (using a simple atomic load) and only executing the select statement when the sink is actually paused, avoiding unnecessary CPU overhead on the critical hot path.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
/gemini summary |
|
/gemini review |
|
@coderabbitai review |
✅ Action performedReview finished.
|
Summary of ChangesThis pull request improves the reliability and shutdown behavior of the region event sink by making the paused push path interruptible. By introducing a 'stopped' atomic flag and refining the synchronization logic, the system can now gracefully handle shutdown signals even when event processing is temporarily paused due to flow control, preventing potential goroutine leaks or hangs. Highlights
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. Activity
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@logservice/logpuller/region_event_sink_test.go`:
- Around line 134-136: The test setup in
TestRegionEventSinkRunCancelUnblocksPush creates a cancellable context but does
not guarantee cleanup if the test exits early. Add a deferred cancel()
immediately after context.WithCancel in this test so the sink.Run(ctx) goroutine
is always unblocked and cannot leak on failure; keep the change localized to the
test helper flow around context creation and cancellation.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 56c63e45-522b-4931-9155-9c07ed766ad2
📒 Files selected for processing (5)
logservice/logpuller/region_event_sink.gologservice/logpuller/region_event_sink_test.gologservice/logpuller/region_request_worker_test.gologservice/logpuller/subscription_client.gologservice/logpuller/subscription_client_test.go
| func TestRegionEventSinkRunCancelUnblocksPush(t *testing.T) { | ||
| ctx, cancel := context.WithCancel(context.Background()) | ||
|
|
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Defer cancel() to avoid leaking Run on early test failure.
If the test fails before Line 163, the goroutine running sink.Run(ctx) can remain blocked on feedback. Add defer cancel() immediately after creating the context. As per coding guidelines, **/*_test.go: Prefer focused deterministic tests; see docs/agents/testing.md before adding or changing tests.
Proposed fix
func TestRegionEventSinkRunCancelUnblocksPush(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
+ defer cancel()
ds := newMockRegionEventSinkStream()📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| func TestRegionEventSinkRunCancelUnblocksPush(t *testing.T) { | |
| ctx, cancel := context.WithCancel(context.Background()) | |
| func TestRegionEventSinkRunCancelUnblocksPush(t *testing.T) { | |
| ctx, cancel := context.WithCancel(context.Background()) | |
| defer cancel() |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@logservice/logpuller/region_event_sink_test.go` around lines 134 - 136, The
test setup in TestRegionEventSinkRunCancelUnblocksPush creates a cancellable
context but does not guarantee cleanup if the test exits early. Add a deferred
cancel() immediately after context.WithCancel in this test so the sink.Run(ctx)
goroutine is always unblocked and cannot leak on failure; keep the change
localized to the test helper flow around context creation and cancellation.
Source: Coding guidelines
There was a problem hiding this comment.
Code Review
This pull request refactors the regionEventSink to manage its lifecycle and flow-control states (paused, stopped) more robustly, removing the context from the struct and introducing helper methods for pausing, resuming, and stopping. It also adds tests to verify that context cancellation unblocks pending push operations. A critical issue was identified in the Run loop where reading from the closed feedback channel of s.ds without checking the ok status can result in an infinite busy loop and high CPU usage during shutdown.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
What problem does this PR solve?
Issue Number: close #5608
What is changed and how it works?
This pull request improves the reliability and shutdown behavior of the region event sink by making the paused push path interruptible. By introducing a 'stopped' atomic flag and refining the synchronization logic, the system can now gracefully handle shutdown signals even when event processing is temporarily paused due to flow control, preventing potential goroutine leaks or hangs.
Highlights
Check List
Tests
Questions
Will it cause performance regression or break compatibility?
Do you need to update user documentation, design documentation or monitoring documentation?
Release note
Summary by CodeRabbit