Skip to content

fix(filter): guard starts and stops in cardano#576

Merged
wolf31o2 merged 1 commit intomainfrom
fix/filter-cardano
Jan 7, 2026
Merged

fix(filter): guard starts and stops in cardano#576
wolf31o2 merged 1 commit intomainfrom
fix/filter-cardano

Conversation

@wolf31o2
Copy link
Copy Markdown
Member

@wolf31o2 wolf31o2 commented Jan 7, 2026

Summary by cubic

Guarded the Cardano filter start/stop lifecycle to prevent race conditions and panics during shutdown. This makes concurrent event processing safer.

  • Bug Fixes
    • Added a sync.WaitGroup to track the processEvents goroutine (Add in Start, Done in processEvents).
    • Stop now closes doneChan, waits for the goroutine to exit, then closes input/output channels.
    • Updated tests to start before stopping and removed assumptions about channels being nil after stop.

Written for commit 03308c5. Summary will update on new commits.

Summary by CodeRabbit

  • Bug Fixes

    • Improved graceful shutdown of the Cardano filter component for more reliable termination.
  • Tests

    • Updated Cardano shutdown tests to validate the complete Start/Stop lifecycle.

✏️ Tip: You can customize this high-level summary in your review settings.

Signed-off-by: Chris Gianelloni <wolf31o2@blinklabs.io>
@wolf31o2 wolf31o2 requested a review from a team as a code owner January 7, 2026 22:52
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jan 7, 2026

📝 Walkthrough

Walkthrough

Changes introduce synchronization using a sync.WaitGroup to the Cardano struct. The Start method increments the wait group before launching the worker goroutine, and the processEvents method defers a Done() call to signal completion. The Stop method now calls Wait() before closing channels. The corresponding test was restructured to call Start before Stop, with removal of post-stop channel-nil assertions.

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: adding synchronization guards (via sync.WaitGroup) to properly coordinate Cardano component starts and stops, ensuring graceful shutdown.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b27d127 and 03308c5.

📒 Files selected for processing (2)
  • filter/cardano/cardano.go
  • filter/cardano/cardano_test.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: Analyze (go)
🔇 Additional comments (5)
filter/cardano/cardano_test.go (1)

157-164: LGTM! Test now properly exercises the Start/Stop lifecycle.

The test correctly calls Start() before Stop(), which properly exercises the shutdown synchronization added in the implementation. Removing the post-stop channel-nil checks is correct since the channels are closed, not set to nil.

filter/cardano/cardano.go (4)

33-33: Excellent addition of WaitGroup for proper shutdown synchronization.

The sync.WaitGroup field correctly enables coordination between the worker goroutine and shutdown logic, preventing the race condition where channels could be closed while the goroutine is still sending events.


55-56: Correct WaitGroup usage in Start().

Calling wg.Add(1) before launching the goroutine follows the proper pattern and ensures the counter is incremented before the worker starts.


62-62: Proper deferred Done() ensures cleanup on all exit paths.

The deferred wg.Done() correctly signals completion when the goroutine exits, regardless of whether it returns via the doneChan signal (line 66) or closed inputChan (line 70).


293-294: Critical fix: Wait for goroutine exit before closing channels.

The wg.Wait() call ensures the processEvents() goroutine has fully exited before closing the channels. This prevents a race condition where the goroutine could panic attempting to send on a closed outputChan (line 77). The shutdown sequence is now safe:

  1. Close doneChan to signal shutdown
  2. Block on wg.Wait() until the worker exits
  3. Close channels safely

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

@wolf31o2 wolf31o2 merged commit 920ef95 into main Jan 7, 2026
10 of 11 checks passed
@wolf31o2 wolf31o2 deleted the fix/filter-cardano branch January 7, 2026 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants