Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/goPublic

Commitd905670

Browse files
rscbradfitz
authored andcommitted
[release-branch.go1.2] database/sql: Use all connections in pool
««« CL 40410043 / 8a7ac002f840database/sql: Use all connections in poolThe last connection in the pool was not being handed out correctly.R=golang-codereviews, gobot, bradfitzCC=golang-codereviewshttps://golang.org/cl/40410043»»»LGTM=rR=golang-codereviews, rCC=golang-devhttps://golang.org/cl/68820044
1 parent402d359 commitd905670

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

‎src/pkg/database/sql/sql.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,8 @@ func (db *DB) conn() (*driverConn, error) {
620620
}
621621

622622
// If db.maxOpen > 0 and the number of open connections is over the limit
623-
//or there are no free connection, then make a request and wait.
624-
ifdb.maxOpen>0&&(db.numOpen>=db.maxOpen||db.freeConn.Len()==0) {
623+
//and there are no free connection, make a request and wait.
624+
ifdb.maxOpen>0&&db.numOpen>=db.maxOpen&&db.freeConn.Len()==0 {
625625
// Make the connRequest channel. It's buffered so that the
626626
// connectionOpener doesn't block while waiting for the req to be read.
627627
ch:=make(chaninterface{},1)

‎src/pkg/database/sql/sql_test.go‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,29 @@ func TestMaxOpenConns(t *testing.T) {
10051005
}
10061006
}
10071007

1008+
funcTestSingleOpenConn(t*testing.T) {
1009+
db:=newTestDB(t,"people")
1010+
defercloseDB(t,db)
1011+
1012+
db.SetMaxOpenConns(1)
1013+
1014+
rows,err:=db.Query("SELECT|people|name|")
1015+
iferr!=nil {
1016+
t.Fatal(err)
1017+
}
1018+
iferr=rows.Close();err!=nil {
1019+
t.Fatal(err)
1020+
}
1021+
// shouldn't deadlock
1022+
rows,err=db.Query("SELECT|people|name|")
1023+
iferr!=nil {
1024+
t.Fatal(err)
1025+
}
1026+
iferr=rows.Close();err!=nil {
1027+
t.Fatal(err)
1028+
}
1029+
}
1030+
10081031
// golang.org/issue/5323
10091032
funcTestStmtCloseDeps(t*testing.T) {
10101033
iftesting.Short() {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp