Fix defer usage
This commit is contained in:
committed by
Jack Christensen
parent
01a6923376
commit
b148a14bbe
@@ -239,27 +239,28 @@ func connect(ctx context.Context, config *Config, fallbackConfig *FallbackConfig
|
|||||||
return nil, &connectError{config: config, msg: "dial error", err: err}
|
return nil, &connectError{config: config, msg: "dial error", err: err}
|
||||||
}
|
}
|
||||||
|
|
||||||
pgConn.contextWatcher = newContextWatcher(netConn)
|
|
||||||
pgConn.contextWatcher.Watch(ctx)
|
|
||||||
defer pgConn.contextWatcher.Unwatch()
|
|
||||||
|
|
||||||
pgConn.status = connStatusConnecting
|
pgConn.status = connStatusConnecting
|
||||||
pgConn.conn = netConn
|
pgConn.conn = netConn
|
||||||
|
|
||||||
|
pgConn.contextWatcher = newContextWatcher(netConn)
|
||||||
|
pgConn.contextWatcher.Watch(ctx)
|
||||||
|
|
||||||
if fallbackConfig.TLSConfig != nil {
|
if fallbackConfig.TLSConfig != nil {
|
||||||
tlsConn, err := startTLS(netConn, fallbackConfig.TLSConfig)
|
tlsConn, err := startTLS(netConn, fallbackConfig.TLSConfig)
|
||||||
|
pgConn.contextWatcher.Unwatch() // Always unwatch `netConn` after TLS.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
netConn.Close()
|
netConn.Close()
|
||||||
return nil, &connectError{config: config, msg: "tls error", err: err}
|
return nil, &connectError{config: config, msg: "tls error", err: err}
|
||||||
}
|
}
|
||||||
|
|
||||||
pgConn.contextWatcher.Unwatch()
|
|
||||||
pgConn.contextWatcher = newContextWatcher(tlsConn)
|
pgConn.contextWatcher = newContextWatcher(tlsConn)
|
||||||
pgConn.contextWatcher.Watch(ctx)
|
pgConn.contextWatcher.Watch(ctx)
|
||||||
|
|
||||||
pgConn.conn = tlsConn
|
pgConn.conn = tlsConn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer pgConn.contextWatcher.Unwatch()
|
||||||
|
|
||||||
pgConn.parameterStatuses = make(map[string]string)
|
pgConn.parameterStatuses = make(map[string]string)
|
||||||
pgConn.frontend = config.BuildFrontend(pgConn.conn, pgConn.conn)
|
pgConn.frontend = config.BuildFrontend(pgConn.conn, pgConn.conn)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user