Fix upstream timeout for large downloads
Some checks failed
docker-release / build-and-push (push) Failing after 25m53s
Some checks failed
docker-release / build-and-push (push) Failing after 25m53s
This commit is contained in:
@@ -31,9 +31,12 @@ func NewUpstreamClient(cfg *config.Config) *http.Client {
|
|||||||
timeout = cfg.Global.UpstreamTimeout.DurationValue()
|
timeout = cfg.Global.UpstreamTimeout.DurationValue()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
transport := defaultTransport.Clone()
|
||||||
|
// Use UpstreamTimeout as ResponseHeaderTimeout to avoid killing long streaming downloads.
|
||||||
|
transport.ResponseHeaderTimeout = timeout
|
||||||
|
|
||||||
return &http.Client{
|
return &http.Client{
|
||||||
Timeout: timeout,
|
Transport: transport,
|
||||||
Transport: defaultTransport.Clone(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,8 +16,12 @@ func TestNewUpstreamClientUsesConfigTimeout(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
client := NewUpstreamClient(cfg)
|
client := NewUpstreamClient(cfg)
|
||||||
if client.Timeout != 45*time.Second {
|
transport, ok := client.Transport.(*http.Transport)
|
||||||
t.Fatalf("expected timeout 45s, got %s", client.Timeout)
|
if !ok {
|
||||||
|
t.Fatalf("expected *http.Transport, got %T", client.Transport)
|
||||||
|
}
|
||||||
|
if transport.ResponseHeaderTimeout != 45*time.Second {
|
||||||
|
t.Fatalf("expected response header timeout 45s, got %s", transport.ResponseHeaderTimeout)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
- `MaxMemoryCacheSize` (bytes, optional, default 268435456)
|
- `MaxMemoryCacheSize` (bytes, optional, default 268435456)
|
||||||
- `MaxRetries` (int >=0, default 3)
|
- `MaxRetries` (int >=0, default 3)
|
||||||
- `InitialBackoff` (duration, default 1s)
|
- `InitialBackoff` (duration, default 1s)
|
||||||
- `UpstreamTimeout` (duration, default 30s)
|
- `UpstreamTimeout` (duration, default 30s, used as upstream response header timeout; body can stream longer)
|
||||||
- **Validation Rules**: 路径必须存在或可创建;数值必须 >0;LogLevel 必须匹配允许枚举。
|
- **Validation Rules**: 路径必须存在或可创建;数值必须 >0;LogLevel 必须匹配允许枚举。
|
||||||
- **Relationships**: 被 `Config` 聚合并为 `HubConfig` 提供默认值。
|
- **Relationships**: 被 `Config` 聚合并为 `HubConfig` 提供默认值。
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user