-
Notifications
You must be signed in to change notification settings - Fork 1k
client: add close method for client pool #797
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1a8e6a9
client: add close method for client pool
RainJoe de658e4
client: remove unused var
RainJoe 6853f76
client: close background goroutine when pool closed
RainJoe a629c76
Update pool.go
RainJoe 28bf4b4
Update resp.go
RainJoe ba716a8
Merge branch 'master' into master
RainJoe 76c71d8
client: replace pool.closed with ctx.Err
RainJoe a3d204b
Merge branch 'master' of https://github.com/RainJoe/go-mysql
RainJoe 5af6a30
client: close background groutine when client pool closed
RainJoe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/go-mysql-org/go-mysql/test_util" | ||
. "github.com/pingcap/check" | ||
"github.com/siddontang/go-log/log" | ||
) | ||
|
||
type poolTestSuite struct { | ||
port string | ||
} | ||
|
||
func (s poolTestSuite) TestPool_Close(c *C) { | ||
addr := fmt.Sprintf("%s:%s", *test_util.MysqlHost, s.port) | ||
pool := NewPool(log.Debugf, 5, 10, 5, addr, *testUser, *testPassword, "") | ||
conn, err := pool.GetConn(context.Background()) | ||
c.Assert(err, IsNil) | ||
err = conn.Ping() | ||
c.Assert(err, IsNil) | ||
pool.PutConn(conn) | ||
pool.Close() | ||
var poolStats ConnectionStats | ||
pool.GetStats(&poolStats) | ||
c.Assert(poolStats.TotalCount, Equals, 0) | ||
c.Assert(pool.readyConnection, HasLen, 0) | ||
_, err = pool.GetConn(context.Background()) | ||
c.Assert(err, NotNil) | ||
} |
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.
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 found another problem, please help me check it.
in line 271,
pool.readyConnection <- connection
may block the for loop. So ifClose
tries to drainpool.readyConnection
first and thennewConnectionProducer
sends at channel, it will become deadlock.Generally, I think a
<-pool.ctx.Done()
branch withpool.readyConnection <- connection
will help to avoid blocking. Andpool.ctx.Err() != nil
can replacepool.closed
.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.
Replacing pool.closed with ctx.Err is a good idea, I wiil update with it. Thanks.