From 9782306287ffc149c499238e31ec6f72e913b4f9 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 11 Nov 2023 09:48:17 -0600 Subject: [PATCH] Only remove statement from map if deallocate succeeds https://github.com/jackc/pgx/pull/1795 --- conn.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/conn.go b/conn.go index b760258c..571f2d35 100644 --- a/conn.go +++ b/conn.go @@ -341,14 +341,23 @@ func (c *Conn) Prepare(ctx context.Context, name, sql string) (sd *pgconn.Statem // Deallocate releases a prepared statement. func (c *Conn) Deallocate(ctx context.Context, name string) error { var psName string - if sd, ok := c.preparedStatements[name]; ok { - delete(c.preparedStatements, name) + sd := c.preparedStatements[name] + if sd != nil { psName = sd.Name } else { psName = name } + err := c.pgConn.Deallocate(ctx, psName) - return err + if err != nil { + return err + } + + if sd != nil { + delete(c.preparedStatements, name) + } + + return nil } // DeallocateAll releases all previously prepared statements from the server and client, where it also resets the statement and description cache.