-
Notifications
You must be signed in to change notification settings - Fork 331
Remove data race. #142
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
base: master
Are you sure you want to change the base?
Remove data race. #142
Conversation
| if p.created < p.max { | ||
| p.makeOne() | ||
| } | ||
| p.makeOne() |
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.
Doesn't this result in unlimited amount of connections?
I believe that the p.created < p.max guard should ensure we only get the specified max connections.
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 believe (and correct me if I'm wrong) that makeOne should be safe to do. It spins up a goroutine that:
- Calls inc()
- inc() will check
p.created >= p.maxand if true, return false
- inc() will check
- If inc() returns false nothing happens
So makeOne should not create a new connection unless p.created < p.max. The benefit to letting makeOne do the logic is that it handles the concurrency better -- it locks the mutex appropriately.
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.
Just checked, you are right.
| } | ||
|
|
||
| func (p *Pool) inc() bool { | ||
| if p.created >= p.max { |
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.
Makes a lot of sense, since it is duplicated.
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.
Is this safe to merge?
This should remove the races detected in #141. Let me know what you think!
Fixes #141