2
0

Ensure pgxpool.Pool.QueryRow.Scan releases connection on panic

Otherwise a connection would be leaked and closing the pool would block.

https://github.com/jackc/pgx/issues/1628
This commit is contained in:
Jack Christensen
2023-06-03 07:39:56 -05:00
parent 229d2aaa49
commit 608f39f426
2 changed files with 26 additions and 0 deletions
+7
View File
@@ -101,7 +101,14 @@ func (row *poolRow) Scan(dest ...any) error {
return row.err
}
panicked := true
defer func() {
if panicked && row.c != nil {
row.c.Release()
}
}()
err := row.r.Scan(dest...)
panicked = false
if row.c != nil {
row.c.Release()
}