2
0

pgx.Conn: Fix memory leak: Delete items from preparedStatements

Previously, items were never removed from the preparedStatements map.
This means workloads that send a large number of unique queries could
run out of memory. Delete items from the map when sending the
deallocate command to Postgres. Add a test to verify this works.

Fixes https://github.com/jackc/pgx/issues/1456
This commit is contained in:
Evan Jones
2023-05-17 13:46:20 -04:00
committed by Jack Christensen
parent eab316e200
commit 0292edecb0
2 changed files with 56 additions and 0 deletions
+1
View File
@@ -1326,6 +1326,7 @@ func (c *Conn) deallocateInvalidatedCachedStatements(ctx context.Context) error
for _, sd := range invalidatedStatements {
pipeline.SendDeallocate(sd.Name)
delete(c.preparedStatements, sd.Name)
}
err := pipeline.Sync()