-
Notifications
You must be signed in to change notification settings - Fork 4
fix(sse): breakline and concurrent write issues #65
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
Conversation
Reviewer's Guide by SourceryThis pull request addresses two issues in the SSE implementation: a data race condition in the Updated class diagram for ConnclassDiagram
class Conn {
-sync.Mutex lock
-string ID
-Streamer s
-context.Context ctx
-chan error done
+Connect(ctx context.Context, s Streamer)
+Send(evt Event) error
+Close() error
}
note for Conn "Added mutex to prevent data race issue on Send"
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Hey @cnlangzi - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider using
sync.Once
to initialize the connection rather than a mutex for every send. - The
PingEvent.Write
method now includes three newlines; is this intentional?
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
@@ -44,7 +45,11 @@ func (r *EventReader) Next() (TextEvent, error) { | |||
} | |||
|
|||
if line == "\n" { | |||
return evt, nil | |||
breakLineNum++ |
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.
suggestion (bug_risk): Handling of consecutive blank lines in EventReader.Next()
The logic increments breakLineNum when encountering a blank line and returns the event only if breakLineNum exceeds 1. Consider whether the breakLineNum should be reset upon receiving a non-blank line so that non-consecutive blank lines do not inadvertently signal event termination.
Suggested implementation:
breakLineNum = 0
if strings.HasPrefix(line, "id:") {
Ensure that the new reset of breakLineNum is implemented for all non-blank lines. You might want to verify any other relevant cases in the function where non-blank lines are processed.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #65 +/- ##
==========================================
+ Coverage 91.21% 91.23% +0.02%
==========================================
Files 62 62
Lines 2537 2545 +8
==========================================
+ Hits 2314 2322 +8
Misses 192 192
Partials 31 31
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Here's the code health analysis summary for commits Analysis Summary
|
Changed
Fixed
Send
Added
Tests
Tasks to complete before merging PR:
make unit-tests
to check for any regressions 📋make lint
to check for any issuesSummary by Sourcery
Fixes issues with server-sent events (SSE) by ensuring proper event data separation and preventing data races during concurrent writes.
Bug Fixes:
Enhancements: