From e8fe9028a3a2ceb9d1a711265bf3779f244a2dae Mon Sep 17 00:00:00 2001 From: Joe Reid Date: Fri, 26 Jan 2018 15:35:45 +0000 Subject: [PATCH] add timeouts for dial requests --- netutil/multidialer.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/netutil/multidialer.go b/netutil/multidialer.go index 9b0b63c..30a8226 100644 --- a/netutil/multidialer.go +++ b/netutil/multidialer.go @@ -86,7 +86,11 @@ func (m *MultiDialer) DialContext(ctx context.Context, network, ignoredAddress s return nil, ctx.Err() default: - conn, err := m.Dialer.DialContext(ctx, network, addr) + // Create new child context for a single dial + dctx, cancel := context.WithTimeout(ctx, time.Second) + defer cancel() + + conn, err := m.Dialer.DialContext(dctx, network, addr) if err != nil { continue }