-
Notifications
You must be signed in to change notification settings - Fork 4
fix wg.Done() #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix wg.Done() #54
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes incorrect wg.Done() calls that were placed in goroutines without corresponding wg.Add() calls. The removed defer wg.Done() statements at lines 98 and 106 were causing WaitGroup synchronization issues since these goroutines were never added to the WaitGroup counter.
Key Changes:
- Removed two incorrect
defer wg.Done()calls from goroutines that handle file output - Reorganized
defer conn.Close()placement (now before error check) - Minor formatting adjustments
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughRemoved WaitGroup completion calls from two per-IP writer goroutines and added an immediate runtime print of the peer IP after creating the gRPC client; no exported API changes. Changes
Sequence Diagram(s)(omitted — changes are limited to minor goroutine sync and logging edits; control flow unchanged) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (3 warnings)
✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
grpc_p2p_client/p2p_client_multi_streams_subscribe.go (1)
96-102: Remove unnecessary wrapper goroutines.The outer goroutine at line 98 immediately launches
writeToFilein a nested goroutine and exits, serving no purpose. This adds unnecessary goroutine overhead. LaunchwriteToFiledirectly instead.Also at: lines 105-109
Apply this diff to remove the wrapper:
if *outputData != "" { dataDone = make(chan bool) - go func() { - header := fmt.Sprintf("receiver\tsender\tsize\tsha256(msg)") - go writeToFile(ctx, dataCh, dataDone, *outputData, header) - }() + header := fmt.Sprintf("receiver\tsender\tsize\tsha256(msg)") + go writeToFile(ctx, dataCh, dataDone, *outputData, header) }Apply similar changes at lines 105-109:
if *outputTrace != "" { traceDone = make(chan bool) - go func() { - header := "" //fmt.Sprintf("sender\tsize\tsha256(msg)") - go writeToFile(ctx, traceCh, traceDone, *outputTrace, header) - }() + header := "" //fmt.Sprintf("sender\tsize\tsha256(msg)") + go writeToFile(ctx, traceCh, traceDone, *outputTrace, header) }
📜 Review details
Configuration used: Repository: getoptimum/coderabbit/.coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (1)
grpc_p2p_client/p2p_client_multi_streams_subscribe.go(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*
⚙️ CodeRabbit configuration file
**/*: When you find the same underlying issue in multiple locations (same pattern, same fix):
- Do NOT post separate comments for each occurrence.
- Post a single primary comment on the first occurrence.
- In that comment, include a short list of “Also at: file:line” references
for the other locations (e.g. 'Also at: foo.go:42, bar.go:17').
Prioritize signal over volume: one strong comment that references multiple
locations is preferred over many near-identical comments.
Files:
grpc_p2p_client/p2p_client_multi_streams_subscribe.go
**/*.go
⚙️ CodeRabbit configuration file
Review Go code for: idiomatic patterns, error handling (check all errors), concurrency safety (context propagation, goroutine cleanup), test coverage for changed logic, exported API stability, memory efficiency (avoid unnecessary allocations), and prefer standard library over third-party when reasonable.
Files:
grpc_p2p_client/p2p_client_multi_streams_subscribe.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). (1)
- GitHub Check: Test Docker Setup
🔇 Additional comments (1)
grpc_p2p_client/p2p_client_multi_streams_subscribe.go (1)
96-128: Synchronization logic is correct after removingwg.Done()from writers.The WaitGroup correctly tracks only the per-IP receiver goroutines (lines 112-118). After receivers complete, channels are closed (lines 121-122), allowing writer goroutines to drain and signal completion via
donechannels (lines 123-128). This separation is proper—writers operate on a different lifecycle than receivers.
Summary by CodeRabbit
Bug Fixes
Chores