Skip to content
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

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft

Weiihann/fix test race #2427

wants to merge 17 commits into from

Conversation

weiihann
Copy link
Contributor

@weiihann weiihann commented Feb 5, 2025

No description provided.

Copy link

codecov bot commented Feb 5, 2025

Codecov Report

Attention: Patch coverage is 71.09375% with 37 lines in your changes missing coverage. Please review.

Project coverage is 74.31%. Comparing base (c646d21) to head (7b9ddae).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
rpc/subscriptions.go 60.67% 33 Missing and 2 partials ⚠️
sync/sync.go 66.66% 2 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

@@ -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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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!

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