pgxpool waits for connection cleanup to finish before making room in pool
refs #679
This commit is contained in:
+7
-2
@@ -190,8 +190,13 @@ func ConnectConfig(ctx context.Context, config *Config) (*Pool, error) {
|
||||
return cr, nil
|
||||
},
|
||||
func(value interface{}) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
value.(*connResource).conn.Close(ctx)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
||||
conn := value.(*connResource).conn
|
||||
conn.Close(ctx)
|
||||
select {
|
||||
case <-conn.PgConn().CleanupChan():
|
||||
case <-ctx.Done():
|
||||
}
|
||||
cancel()
|
||||
},
|
||||
config.MaxConns,
|
||||
|
||||
@@ -609,6 +609,12 @@ func TestConnReleaseWhenBeginFail(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
stats := db.Stat()
|
||||
assert.EqualValues(t, 0, stats.TotalConns())
|
||||
for i := 0; i < 1000; i++ {
|
||||
if db.Stat().TotalConns() == 0 {
|
||||
break
|
||||
}
|
||||
time.Sleep(time.Millisecond)
|
||||
}
|
||||
|
||||
assert.EqualValues(t, 0, db.Stat().TotalConns())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user