@@ -288,6 +288,13 @@ func connect(ctx context.Context, config *Config, fallbackConfig *FallbackConfig
|
|||||||
case *pgproto3.ReadyForQuery:
|
case *pgproto3.ReadyForQuery:
|
||||||
pgConn.status = connStatusIdle
|
pgConn.status = connStatusIdle
|
||||||
if config.ValidateConnect != nil {
|
if config.ValidateConnect != nil {
|
||||||
|
// ValidateConnect may execute commands that cause the context to be watched again. Unwatch first to avoid
|
||||||
|
// the watch already in progress panic. This is that last thing done by this method so there is no need to
|
||||||
|
// restart the watch after ValidateConnect returns.
|
||||||
|
//
|
||||||
|
// See https://github.com/jackc/pgconn/issues/40.
|
||||||
|
pgConn.contextWatcher.Unwatch()
|
||||||
|
|
||||||
err := config.ValidateConnect(ctx, pgConn)
|
err := config.ValidateConnect(ctx, pgConn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
pgConn.conn.Close()
|
pgConn.conn.Close()
|
||||||
|
|||||||
+5
-2
@@ -346,9 +346,12 @@ func TestConnectWithValidateConnectTargetSessionAttrsReadWrite(t *testing.T) {
|
|||||||
config.ValidateConnect = pgconn.ValidateConnectTargetSessionAttrsReadWrite
|
config.ValidateConnect = pgconn.ValidateConnectTargetSessionAttrsReadWrite
|
||||||
config.RuntimeParams["default_transaction_read_only"] = "on"
|
config.RuntimeParams["default_transaction_read_only"] = "on"
|
||||||
|
|
||||||
conn, err := pgconn.ConnectConfig(context.Background(), config)
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
conn, err := pgconn.ConnectConfig(ctx, config)
|
||||||
if !assert.NotNil(t, err) {
|
if !assert.NotNil(t, err) {
|
||||||
conn.Close(context.Background())
|
conn.Close(ctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user