Skip to content

Commit

Permalink
[-] fix pool after release handler to avoid session termination causi…
Browse files Browse the repository at this point in the history
…ng 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`
  • Loading branch information
pashagolub authored Nov 15, 2023
1 parent d136402 commit e483cf5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions internal/migrator/migrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func migrateTest() error {
if err != nil {
return err
}
defer pge.Finalize()
_, _ = pge.ConfigDb.Exec(ctx, "DROP TABLE IF EXISTS foo, bar, baz, migration")
db, err := pge.ConfigDb.Acquire(ctx)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion internal/pgengine/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,13 @@ func (pge *PgEngine) getPgxConnConfig() *pgxpool.Config {
// some objects and/or setting changes will still exist in the session
connConfig.AfterRelease = func(pgconn *pgx.Conn) bool {
var err error
if pgconn.DeallocateAll(context.Background()) != nil {
return false // destroy the connection in case of error
}
if _, err = pgconn.Exec(context.Background(), "DISCARD ALL"); err == nil {
_, err = pgconn.Exec(context.Background(), "LISTEN "+quoteIdent(pge.ClientName))
}
return err != nil
return err == nil
}

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

0 comments on commit e483cf5

Please sign in to comment.