Open
Conversation
bosim
reviewed
Mar 10, 2021
| if p.created < p.max { | ||
| p.makeOne() | ||
| } | ||
| p.makeOne() |
Contributor
There was a problem hiding this comment.
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.
Author
There was a problem hiding this comment.
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.
Contributor
There was a problem hiding this comment.
Just checked, you are right.
bosim
reviewed
Mar 10, 2021
| } | ||
|
|
||
| func (p *Pool) inc() bool { | ||
| if p.created >= p.max { |
Contributor
There was a problem hiding this comment.
Makes a lot of sense, since it is duplicated.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This should remove the races detected in #141. Let me know what you think!
Fixes #141