logpuller: fix potential shutdown hang in paused region event push#5610
Conversation
|
Skipping CI for Draft Pull Request. |
|
Warning Review limit reached
Next review available in: 48 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
ChangesregionEventSink shutdown coordination
Estimated code review effort: 3 (Moderate) | ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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.
48aa828 to
52d0c39
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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`:
- Line 137: Remove the stray “<<<<<<< HEAD” merge-conflict marker from
region_event_sink_test.go and resolve any related conflict remnants, including
“=======” and “>>>>>>>” markers, while preserving the intended test code so the
package compiles.
- Around line 159-162: Replace the regionEventSink literal in both subtests with
newTestRegionEventSink(ds), since stopCh was removed and the helper also
initializes cond consistently.
🪄 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: d8a3cb28-28fc-41fd-a3bd-fb8966d187e3
📒 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
🚧 Files skipped from review as they are similar to previous changes (3)
- logservice/logpuller/subscription_client_test.go
- logservice/logpuller/region_request_worker_test.go
- logservice/logpuller/subscription_client.go
|
/test all |
|
/retest |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: asddongmen, hongyunyan The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
[LGTM Timeline notifier]Timeline:
|
|
/retest |
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
Pushoperations unblock promptly on run cancellation, improving pause/resume reliability.