@@ -24,6 +24,17 @@ func init() {
24
24
c * driverConn
25
25
}
26
26
freedFrom := make (map [dbConn ]string )
27
+ var mu sync.Mutex
28
+ getFreedFrom := func (c dbConn ) string {
29
+ mu .Lock ()
30
+ defer mu .Unlock ()
31
+ return freedFrom [c ]
32
+ }
33
+ setFreedFrom := func (c dbConn , s string ) {
34
+ mu .Lock ()
35
+ defer mu .Unlock ()
36
+ freedFrom [c ] = s
37
+ }
27
38
putConnHook = func (db * DB , c * driverConn ) {
28
39
idx := - 1
29
40
for i , v := range db .freeConn {
@@ -36,10 +47,10 @@ func init() {
36
47
// print before panic, as panic may get lost due to conflicting panic
37
48
// (all goroutines asleep) elsewhere, since we might not unlock
38
49
// the mutex in freeConn here.
39
- println ("double free of conn. conflicts are:\n A) " + freedFrom [ dbConn {db , c }] + "\n \n and\n B) " + stack ())
50
+ println ("double free of conn. conflicts are:\n A) " + getFreedFrom ( dbConn {db , c }) + "\n \n and\n B) " + stack ())
40
51
panic ("double free of conn." )
41
52
}
42
- freedFrom [ dbConn {db , c }] = stack ()
53
+ setFreedFrom ( dbConn {db , c }, stack () )
43
54
}
44
55
}
45
56
@@ -344,7 +355,7 @@ func TestQueryContextWait(t *testing.T) {
344
355
// This will trigger the *fakeConn.Prepare method which will take time
345
356
// performing the query. The ctxDriverPrepare func will check the context
346
357
// after this and close the rows and return an error.
347
- _ , err := db .QueryContext (ctx , "WAIT|30ms |SELECT|people|age,name|" )
358
+ _ , err := db .QueryContext (ctx , "WAIT|1s |SELECT|people|age,name|" )
348
359
if err != context .DeadlineExceeded {
349
360
t .Fatalf ("expected QueryContext to error with context deadline exceeded but returned %v" , err )
350
361
}
@@ -372,7 +383,7 @@ func TestTxContextWait(t *testing.T) {
372
383
// This will trigger the *fakeConn.Prepare method which will take time
373
384
// performing the query. The ctxDriverPrepare func will check the context
374
385
// after this and close the rows and return an error.
375
- _ , err = tx .QueryContext (ctx , "WAIT|30ms |SELECT|people|age,name|" )
386
+ _ , err = tx .QueryContext (ctx , "WAIT|1s |SELECT|people|age,name|" )
376
387
if err != context .DeadlineExceeded {
377
388
t .Fatalf ("expected QueryContext to error with context deadline exceeded but returned %v" , err )
378
389
}
0 commit comments