Skip to content

database/sql: dangling statement(s) #5936

@alexbrainman

Description

@alexbrainman
Discovered while investigating https://code.google.com/p/odbc/issues/detail?id=12

If I add this:

diff --git a/src/pkg/database/sql/sql_test.go b/src/pkg/database/sql/sql_test.go
--- a/src/pkg/database/sql/sql_test.go
+++ b/src/pkg/database/sql/sql_test.go
@@ -1046,6 +1046,20 @@
    }
 }
 
+func TestStmtCloseOrder(t *testing.T) {
+   db := newTestDB(t, "people")
+   defer closeDB(t, db)
+
+   db.SetMaxIdleConns(0)
+   setStrictFakeConnClose(t)
+   defer setStrictFakeConnClose(nil)
+
+   _, err := db.Query("SELECT|non_existent|name|")
+   if err == nil {
+       t.Fatal("Quering non-existent table should fail")
+   }
+}
+
 func manyConcurrentQueries(t testOrBench) {
    maxProcs, numReqs := 16, 500
    if testing.Short() {

then test fails with

# go test                                                                    
--- FAIL: TestStmtCloseOrder (0.00 seconds)                                          
        fakedb_test.go:257: failed to close a test fakeConn: can't close; dangling statement(s)                                                                           
FAIL                                                                                 
exit status 1                                                                        
FAIL    database/sql    0.179s                                                       
# hg id                                                                      
e6a6dc0d9c22+ tip                                                                    
#                                                                            

I am not familiar with source code, but I think https://golang.org/cl/11620046
should fix the problem.

Alex

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions