Describe the bug
conn from instance.Conn(context.Background()) is not closed when the function returns an error after that point but before successful return such as in
.
Also, it is pretty lousy to use context.Background() throughout this file instead of plumbing through contexts.
Steps to reproduce the behavior:
If possible, please provide runnable example such as:
package main
func main() {
dbPool, err := pgxpool.New(ctx, dbURL())
if err != nil {
return fmt.Errorf("unable to create connection pool: %w", err)
}
defer dbPool.Close()
instance := stdlib.OpenDBFromPool(pool)
defer func() {
if err := instance.Close(); err != nil {
slog.Error("failed to close database instance", "error", err)
}
}()
driver, err := pgx.WithInstance(instance, &pgx.Config{})
if err != nil {
return nil, fmt.Errorf("failed to create migration driver: %w", err)
}
defer func() {
if err := driver.Close(); err != nil {
slog.Error("failed to close migration driver", "error", err)
}
}()
}
If ensureversiontable errors out with for example a user permission issue, the conn is leaked instead of being closed.
Expected behavior
Resources allocated are managed in all code paths
Actual behavior
leaked conn blocking pool closure
Migrate Version
github.com/golang-migrate/migrate/v4 v4.19.1
Loaded Drivers
github.com/jackc/pgx/v5 v5.8.0
Go Version
go version go1.26.0 darwin/arm64
Stacktrace
N/A
Additional context
Add any other context about the problem here.
Describe the bug
conn from instance.Conn(context.Background()) is not closed when the function returns an error after that point but before successful return such as in
migrate/database/pgx/v5/pgx.go
Line 133 in 257fa84
Also, it is pretty lousy to use context.Background() throughout this file instead of plumbing through contexts.
Steps to reproduce the behavior:
If possible, please provide runnable example such as:
If ensureversiontable errors out with for example a user permission issue, the conn is leaked instead of being closed.
Expected behavior
Resources allocated are managed in all code paths
Actual behavior
leaked conn blocking pool closure
Migrate Version
github.com/golang-migrate/migrate/v4 v4.19.1
Loaded Drivers
github.com/jackc/pgx/v5 v5.8.0
Go Version
go version go1.26.0 darwin/arm64
Stacktrace
N/A
Additional context
Add any other context about the problem here.