FAQ
Reviewers: golang-dev1,

Message:
Hello golang-dev@googlegroups.com,

I'd like you to review this change to
https://code.google.com/p/go


Description:
database/sql: Use all connections in pool

The last connection in the pool was not being handed out correctly.

Please review this at https://codereview.appspot.com/40410043/

Affected files (+25, -2 lines):
    M src/pkg/database/sql/sql.go
    M src/pkg/database/sql/sql_test.go


Index: src/pkg/database/sql/sql.go
===================================================================
--- a/src/pkg/database/sql/sql.go
+++ b/src/pkg/database/sql/sql.go
@@ -620,8 +620,8 @@
    }

    // If db.maxOpen > 0 and the number of open connections is over the limit
- // or there are no free connection, then make a request and wait.
- if db.maxOpen > 0 && (db.numOpen >= db.maxOpen || db.freeConn.Len() == 0)
{
+ // and there are no free connection, make a request and wait.
+ if db.maxOpen > 0 && db.numOpen >= db.maxOpen && db.freeConn.Len() == 0 {
     // Make the connRequest channel. It's buffered so that the
     // connectionOpener doesn't block while waiting for the req to be read.
     ch := make(chan interface{}, 1)
Index: src/pkg/database/sql/sql_test.go
===================================================================
--- a/src/pkg/database/sql/sql_test.go
+++ b/src/pkg/database/sql/sql_test.go
@@ -1005,6 +1005,29 @@
    }
   }

+func TestSingleOpenConn(t *testing.T) {
+ db := newTestDB(t, "people")
+ defer closeDB(t, db)
+
+ db.SetMaxOpenConns(1)
+
+ rows, err := db.Query("SELECT|people|name|")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err = rows.Close(); err != nil {
+ t.Fatal(err)
+ }
+ // shouldn't deadlock
+ rows, err = db.Query("SELECT|people|name|")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err = rows.Close(); err != nil {
+ t.Fatal(err)
+ }
+}
+
   // golang.org/issue/5323
   func TestStmtCloseDeps(t *testing.T) {
    if testing.Short() {


--

---
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedDec 10, '13 at 7:27p
activeDec 10, '13 at 7:27p
posts1
users1
websitegolang.org

1 user in discussion

Marko: 1 post

People

Translate

site design / logo © 2022 Grokbase