Fix goroutines change DialContext of http.DefaultTransport in router (#1063)

This commit is contained in:
Ta-Ching Chen
2019-01-26 04:48:10 +08:00
committed by GitHub
parent b5b689973b
commit f24b016346
+21 -4
View File
@@ -183,10 +183,7 @@ func (roundTripper RetryingRoundTripper) RoundTrip(req *http.Request) (resp *htt
}
// set the timeout for transport context
transport := http.DefaultTransport.(*http.Transport)
// Disables caching, Please refer to issue and specifically comment: https://github.com/fission/fission/issues/723#issuecomment-398781995
transport.DisableKeepAlives = true
transport := roundTripper.getDefaultTransport()
executingTimeout := roundTripper.funcHandler.tsRoundTripperParams.timeout
@@ -346,6 +343,26 @@ func (roundTripper RetryingRoundTripper) RoundTrip(req *http.Request) (resp *htt
return resp, err
}
// getDefaultTransport returns a pointer to new copy of http.Transport object to prevent
// the value of http.DefaultTransport from being changed by goroutines.
func (roundTripper RetryingRoundTripper) getDefaultTransport() *http.Transport {
// The transport setup here follows the configurations of http.DefaultTransport
// but without Dialer since we will change it later.
transport := http.Transport{
Proxy: http.ProxyFromEnvironment,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}
// Disables caching, Please refer to issue and specifically
// comment: https://github.com/fission/fission/issues/723#issuecomment-398781995
transport.DisableKeepAlives = true
return &transport
}
func (fh *functionHandler) tapService(serviceUrl *url.URL) {
if fh.executor == nil {
return