Skip to content

Commit e483cf5

Browse files
authored
[-] fix pool after release handler to avoid session termination causing side effects (#615)
* [-] fix pool after release handler to avoid session termination causing side effects * [-] deallocate all internal prepared statements before DISCARD * [-] fix `migrateTest` to close opened `pgengine`
1 parent d136402 commit e483cf5

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

internal/migrator/migrator_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func migrateTest() error {
5555
if err != nil {
5656
return err
5757
}
58+
defer pge.Finalize()
5859
_, _ = pge.ConfigDb.Exec(ctx, "DROP TABLE IF EXISTS foo, bar, baz, migration")
5960
db, err := pge.ConfigDb.Acquire(ctx)
6061
if err != nil {

internal/pgengine/bootstrap.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,13 @@ func (pge *PgEngine) getPgxConnConfig() *pgxpool.Config {
184184
// some objects and/or setting changes will still exist in the session
185185
connConfig.AfterRelease = func(pgconn *pgx.Conn) bool {
186186
var err error
187+
if pgconn.DeallocateAll(context.Background()) != nil {
188+
return false // destroy the connection in case of error
189+
}
187190
if _, err = pgconn.Exec(context.Background(), "DISCARD ALL"); err == nil {
188191
_, err = pgconn.Exec(context.Background(), "LISTEN "+quoteIdent(pge.ClientName))
189192
}
190-
return err != nil
193+
return err == nil
191194
}
192195

193196
if !pge.Start.Debug { //will handle notification in HandleNotifications directly

0 commit comments

Comments
 (0)