From 10d5f5eaa82ba291c4a0eaa7086a2d4b3130310a Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 12 Oct 2019 11:06:43 -0500 Subject: [PATCH] Do not mutate config.Config.OnNotification in connect fixes #618 --- conn.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/conn.go b/conn.go index 5515dddc..58195f1f 100644 --- a/conn.go +++ b/conn.go @@ -169,6 +169,13 @@ func connect(ctx context.Context, config *ConnConfig) (c *Conn, err error) { panic("config must be created by ParseConfig") } + // This isn't really a deep copy. But it is enough to avoid the config.Config.OnNotification mutation from affecting + // other connections with the same config. See https://github.com/jackc/pgx/issues/618. + { + configCopy := *config + config = &configCopy + } + c = &Conn{ config: config, connInfo: pgtype.NewConnInfo(),