Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically increase ConnectTimeout to be >= 2xDialTimeout #707

Merged
merged 2 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions command/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ func (c *command) runE(cmd *cobra.Command, _ []string) (cmdErr error) {
}
}

if 2*c.httpTransportConfig.DialTimeout > c.httpProxyConfig.ConnectTimeout {
c.httpProxyConfig.ConnectTimeout = 2 * c.httpTransportConfig.DialTimeout
}

g := runctx.NewGroup()
{
p, err := forwarder.NewHTTPProxy(c.httpProxyConfig, pr, cm, rt, logger.Named("proxy"))
Expand Down
4 changes: 3 additions & 1 deletion http_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ type HTTPProxyConfig struct {
ResponseModifiers []ResponseModifier
ConnectRequestModifier func(*http.Request) error
ConnectFunc ConnectFunc
ConnectTimeout time.Duration
ReadLimit SizeSuffix
WriteLimit SizeSuffix

Expand All @@ -113,6 +114,7 @@ func DefaultHTTPProxyConfig() *HTTPProxyConfig {
Name: "forwarder",
ProxyLocalhost: DenyProxyLocalhost,
RequestIDHeader: "X-Request-Id",
ConnectTimeout: 60 * time.Second,
}
}

Expand Down Expand Up @@ -234,7 +236,7 @@ func (hp *HTTPProxy) configureProxy() error {
hp.proxy.RequestIDHeader = hp.config.RequestIDHeader
hp.proxy.ConnectRequestModifier = hp.config.ConnectRequestModifier
hp.proxy.ConnectFunc = hp.config.ConnectFunc
hp.proxy.ConnectTimeout = 60 * time.Second
hp.proxy.ConnectTimeout = hp.config.ConnectTimeout
hp.proxy.WithoutWarning = true
hp.proxy.ErrorResponse = hp.errorResponse
hp.proxy.IdleTimeout = hp.config.IdleTimeout
Expand Down
Loading