Skip to content

[client] fix goroutine leak in TestReceive_ProtocolErrorStreamReconnect#5951

Merged
pappz merged 1 commit intomainfrom
fix/flow-client-test-receive-goroutine-leak
Apr 21, 2026
Merged

[client] fix goroutine leak in TestReceive_ProtocolErrorStreamReconnect#5951
pappz merged 1 commit intomainfrom
fix/flow-client-test-receive-goroutine-leak

Conversation

@pappz
Copy link
Copy Markdown
Collaborator

@pappz pappz commented Apr 21, 2026

Describe your changes

The Receive goroutine could outlive the test and call t.Logf after teardown, panicking with "Log in goroutine after ... has completed". Register a cleanup that waits for the goroutine to exit; ordering is LIFO so it runs after client.Close, which is what unblocks Receive.

Issue ticket number and link

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

https://github.com/netbirdio/docs/pull/__

Summary by CodeRabbit

  • Tests
    • Improved test reliability by ensuring proper synchronization and cleanup of goroutines in protocol error handling tests.

The Receive goroutine could outlive the test and call t.Logf after
teardown, panicking with "Log in goroutine after ... has completed".
Register a cleanup that waits for the goroutine to exit; ordering is
LIFO so it runs after client.Close, which is what unblocks Receive.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 21, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 00b9ce26-11c6-4714-ac15-fa3d87994ccf

📥 Commits

Reviewing files that changed from the base of the PR and between 064ec1c and b716b20.

📒 Files selected for processing (1)
  • flow/client/client_test.go

📝 Walkthrough

Walkthrough

A test synchronization improvement was added to TestReceive_ProtocolErrorStreamReconnect to ensure the client.Receive goroutine properly terminates before test cleanup. The change uses a channel-based mechanism to signal goroutine completion with a 2-second timeout.

Changes

Cohort / File(s) Summary
Test Synchronization
flow/client/client_test.go
Added a receiveDone channel and cleanup handler to wait for goroutine termination, with defer-based signaling to ensure completion regardless of exit path.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • lixmal

Poem

🐰 A channel to close, a goroutine to wait,
No race to the finish, no test-cleanup fate!
With cleanup and signals, so tidy and neat,
The teardown now waits for the goroutine's retreat! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: fixing a goroutine leak in a specific test function.
Description check ✅ Passed The description covers the required template sections with clear explanation of the bug, includes the bug fix checkbox, and addresses documentation needs appropriately.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/flow-client-test-receive-goroutine-leak

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.

@sonarqubecloud
Copy link
Copy Markdown

@pappz pappz merged commit 703353d into main Apr 21, 2026
42 checks passed
@pappz pappz deleted the fix/flow-client-test-receive-goroutine-leak branch April 21, 2026 17:06
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.

2 participants