From 7511806ec2914f9d9b6a8941d420fb0443f5f5f6 Mon Sep 17 00:00:00 2001 From: Todd Neal Date: Thu, 18 Jun 2015 07:26:39 -0500 Subject: [PATCH] net/http: fix race on postPendingDial test hook The race occurs rarely, but by putting some delays and more reads/writes of prePendingDial/postPendingDial in the handlePendingDial function I could reproduce it. Fixes #11136 Change-Id: I8da9e66c88fbda049eaaaaffa2717264ef327768 Reviewed-on: https://go-review.googlesource.com/11250 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick --- src/net/http/transport.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/net/http/transport.go b/src/net/http/transport.go index 70797ddfe7e7ea..e4854e8a146402 100644 --- a/src/net/http/transport.go +++ b/src/net/http/transport.go @@ -523,6 +523,11 @@ func (t *Transport) getConn(req *Request, cm connectMethod) (*persistConn, error } dialc := make(chan dialRes) + // Copy these hooks so we don't race on the postPendingDial in + // the goroutine we launch. Issue 11136. + prePendingDial := prePendingDial + postPendingDial := postPendingDial + handlePendingDial := func() { if prePendingDial != nil { prePendingDial()