Store original config in Conn before updating it.

pull/768/head
georgysavva 2020-06-01 19:38:12 +03:00
parent 0e04d8187e
commit 608451a215
3 changed files with 3 additions and 3 deletions

View File

@ -174,6 +174,7 @@ func connect(ctx context.Context, config *ConnConfig) (c *Conn, err error) {
if !config.createdByParseConfig {
panic("config must be created by ParseConfig")
}
originalConfig := config
// 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.
@ -183,7 +184,7 @@ func connect(ctx context.Context, config *ConnConfig) (c *Conn, err error) {
}
c = &Conn{
config: config,
config: originalConfig,
connInfo: pgtype.NewConnInfo(),
logLevel: config.LogLevel,
logger: config.Logger,

View File

@ -51,7 +51,7 @@ func TestConnect(t *testing.T) {
t.Fatalf("Unable to establish connection: %v", err)
}
assert.Equal(t, connString, conn.Config().ConnString())
assert.Equal(t, config, conn.Config())
var currentDB string
err = conn.QueryRow(context.Background(), "select current_database()").Scan(&currentDB)

1
go.mod
View File

@ -14,7 +14,6 @@ require (
github.com/shopspring/decimal v0.0.0-20200227202807-02e2044944cc
github.com/sirupsen/logrus v1.4.2
github.com/stretchr/testify v1.5.1
go.uber.org/multierr v1.5.0 // indirect
go.uber.org/zap v1.10.0
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec