+1
-1
@@ -27,7 +27,7 @@ func (c *Conn) Release() {
|
||||
c.res = nil
|
||||
|
||||
now := time.Now()
|
||||
if conn.IsClosed() || conn.PgConn().TxStatus() != 'I' || (now.Sub(res.CreationTime()) > c.p.maxConnLifetime) {
|
||||
if conn.IsClosed() || conn.PgConn().IsBusy() || conn.PgConn().TxStatus() != 'I' || (now.Sub(res.CreationTime()) > c.p.maxConnLifetime) {
|
||||
res.Destroy()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -210,6 +210,26 @@ func TestConnReleaseChecksMaxConnLifetime(t *testing.T) {
|
||||
assert.EqualValues(t, 0, stats.TotalConns())
|
||||
}
|
||||
|
||||
func TestConnReleaseClosesBusyConn(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db, err := pgxpool.Connect(context.Background(), os.Getenv("PGX_TEST_DATABASE"))
|
||||
require.NoError(t, err)
|
||||
defer db.Close()
|
||||
|
||||
c, err := db.Acquire(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = c.Query(context.Background(), "select generate_series(1,10)")
|
||||
require.NoError(t, err)
|
||||
|
||||
c.Release()
|
||||
waitForReleaseToComplete()
|
||||
|
||||
stats := db.Stat()
|
||||
assert.EqualValues(t, 0, stats.TotalConns())
|
||||
}
|
||||
|
||||
func TestPoolBackgroundChecksMaxConnLifetime(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user