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}
|
||||
}
|
||||
|
||||
pgConn.contextWatcher = newContextWatcher(netConn)
|
||||
pgConn.contextWatcher.Watch(ctx)
|
||||
defer pgConn.contextWatcher.Unwatch()
|
||||
|
||||
pgConn.status = connStatusConnecting
|
||||
pgConn.conn = netConn
|
||||
|
||||
pgConn.contextWatcher = newContextWatcher(netConn)
|
||||
pgConn.contextWatcher.Watch(ctx)
|
||||
|
||||
if fallbackConfig.TLSConfig != nil {
|
||||
tlsConn, err := startTLS(netConn, fallbackConfig.TLSConfig)
|
||||
pgConn.contextWatcher.Unwatch() // Always unwatch `netConn` after TLS.
|
||||
if err != nil {
|
||||
netConn.Close()
|
||||
return nil, &connectError{config: config, msg: "tls error", err: err}
|
||||
}
|
||||
|
||||
pgConn.contextWatcher.Unwatch()
|
||||
pgConn.contextWatcher = newContextWatcher(tlsConn)
|
||||
pgConn.contextWatcher.Watch(ctx)
|
||||
|
||||
pgConn.conn = tlsConn
|
||||
}
|
||||
|
||||
defer pgConn.contextWatcher.Unwatch()
|
||||
|
||||
pgConn.parameterStatuses = make(map[string]string)
|
||||
pgConn.frontend = config.BuildFrontend(pgConn.conn, pgConn.conn)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user