upstream: use context to set connectToUpstream timeout

This allows the timeout to apply to the whole sequence of
operations, as opposed to just Dial.
This commit is contained in:
Simon Ser 2022-04-14 19:42:02 +02:00
parent b790db1423
commit 2ba13fdefc

View File

@ -150,7 +150,10 @@ type upstreamConn struct {
func connectToUpstream(ctx context.Context, network *network) (*upstreamConn, error) { func connectToUpstream(ctx context.Context, network *network) (*upstreamConn, error) {
logger := &prefixLogger{network.user.logger, fmt.Sprintf("upstream %q: ", network.GetName())} logger := &prefixLogger{network.user.logger, fmt.Sprintf("upstream %q: ", network.GetName())}
dialer := net.Dialer{Timeout: connectTimeout} ctx, cancel := context.WithTimeout(ctx, connectTimeout)
defer cancel()
var dialer net.Dialer
u, err := network.URL() u, err := network.URL()
if err != nil { if err != nil {