2
0

Releasing a busy connection closes the connection

refs #622
This commit is contained in:
Jack Christensen
2019-10-12 11:26:51 -05:00
parent 0e52829a07
commit 93a2aa5b2f
5 changed files with 28 additions and 2 deletions
+1 -1
View File
@@ -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
}
+20
View File
@@ -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()