net/http/httputil: fix race/crash in previous ReverseProxy change
net/http/httputil: fix race/crash in previous ReverseProxy change

The previous ReverseProxy change, CL 137335, introduced a bug which could cause
a race and/or a crash.

This reliably crashed before:

$ go test -short -race -v -run=TestReverseProxyFlushInterval -count=20 net/http/httputil

The problem was a goroutine was running http.ResponseWriter.Flush
after the http.Handler's ServeHTTP completed. There was code to
prevent that (a deferred stop call) but the stop call didn't consider
the case where time.AfterFunc had already fired off a new goroutine
but that goroutine hadn't yet scheduled.

Change-Id: I06357908465a3b953efc33e63c70dec19a501adf
Reviewed-on: https://go-review.googlesource.com/c/140977
Run-TryBot: Brad Fitzpatrick <ae9783c0b0efc69cd85ab025ddd17aa44cdc4aa5@golang.org>
TryBot-Result: Gobot Gobot <66cb808b70d30c07676d5e946fee83fd561249e5@golang.org>
Reviewed-by: Dmitri Shuralyov <d181b7fea0ec87c86ba5a890ab716db52498e3ba@golang.org>

akutz/go,josharian/go,josharian/go,nawawi/go,nawawi/go,CAFxX/go,nawawi/go,akutz/go,josharian/go,josharian/go,akutz/go,cloudflare/go,nawawi/go,cloudflare/go,nawawi/go,CAFxX/go,CAFxX/go,cloudflare/go,golang/go,josharian/go,nawawi/go,CAFxX/go,nawawi/go,CAFxX/go,akutz/go,cloudflare/go,CAFxX/go,cloudflare/go,josharian/go,akutz/go,golang/go,golang/go,cloudflare/go,josharian/go,akutz/go,akutz/go,CAFxX/go,nawawi/go,golang/go,CAFxX/go,golang/go,golang/go,golang/go,golang/go,cloudflare/go,cloudflare/go,akutz/go,josharian/go