cloudfoundry / gorouter

CF Router
Apache License 2.0
441 stars 226 forks source link

Protect against data race when ReverseProxy modifies response headers #388

Closed mariash closed 9 months ago

mariash commented 9 months ago

See issue: https://github.com/golang/go/issues/65123

ReverseProxy configures Got1xxResponse trace hook. We configure ReverseProxy with our ProxyRoundTripper. ProxyRoundTripper eventually calls http.Transport.

http.Transport runs readLoop for each connection in a separate goroutine. When RoundTrip is called readLoop will run Got1xxResponse hook.

If there are no errors during request handling, RoundTrip waits for readLoop to finish. If there is an error though RoundTrip exits early and does not wait for readLoop to finish. This results in readLoop goroutine running in parallel and we get a data race in our ErrorHandler which modifies response headers at the same time as Got1xxResponse hook.

This error results in concurrent map writes and not panic, which is not caught by panic handler making Gorouter fail and drop all connections.

This code can be removed once the ReverseProxy issue is fixed.