-
Notifications
You must be signed in to change notification settings - Fork 196
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
Weiihann/fix test race #2427
base: main
Are you sure you want to change the base?
Weiihann/fix test race #2427
Conversation
fix nil blockid interface
remove equal
This reverts commit 48b4202.
Co-authored-by: Daniil Ankushin <ankushin.daniil42@gmail.com> Signed-off-by: Ng Wei Han <47109095+weiihann@users.noreply.github.com>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2427 +/- ##
==========================================
- Coverage 74.55% 74.31% -0.25%
==========================================
Files 113 113
Lines 13040 13124 +84
==========================================
+ Hits 9722 9753 +31
- Misses 2588 2633 +45
- Partials 730 738 +8 ☔ View full report in Codecov by Sentry. |
@@ -49,12 +63,23 @@ func (ws *Websocket) WithListener(listener NewRequestListener) *Websocket { | |||
// ServeHTTP processes an HTTP request and upgrades it to a websocket connection. | |||
// The connection's entire "lifetime" is spent in this function. | |||
func (ws *Websocket) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |||
// Check connection limit | |||
if ws.connCount.Load() >= ws.maxConns { |
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.
I think race condition can cause the connection count going over the limit. For example, 2 requests reach this at the same time when the connCount
is 2047, both of them will pass this check and acquire a new connection.
I think a simpler option to consider is to use https://pkg.go.dev/golang.org/x/sync@v0.11.0/semaphore.
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.
You're right, thanks for catching that!
No description provided.