Fix network URLs in serve: loopback agents, own-origin public URLs, longer transfer timeouts
This commit is contained in:
@@ -48,6 +48,12 @@ type Client struct {
|
||||
}
|
||||
|
||||
func NewClient(baseURL string, tokens TokenProvider, timeout time.Duration) *Client {
|
||||
// Payload transfers get a more generous budget than control calls: a large
|
||||
// shard over a slow link easily outlives the API timeout.
|
||||
transferTimeout := timeout * 4
|
||||
if transferTimeout < 2*time.Minute {
|
||||
transferTimeout = 2 * time.Minute
|
||||
}
|
||||
return &Client{
|
||||
baseURL: strings.TrimRight(baseURL, "/"),
|
||||
tokens: tokens,
|
||||
@@ -57,7 +63,7 @@ func NewClient(baseURL string, tokens TokenProvider, timeout time.Duration) *Cli
|
||||
CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse },
|
||||
},
|
||||
dlClient: &http.Client{
|
||||
Timeout: timeout,
|
||||
Timeout: transferTimeout,
|
||||
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
||||
if len(via) >= 10 {
|
||||
return fmt.Errorf("too many redirects")
|
||||
|
||||
@@ -223,3 +223,17 @@ func sha256Of(t *testing.T, value string) string {
|
||||
digest := sha256.Sum256([]byte(value))
|
||||
return fmt.Sprintf("%x", digest)
|
||||
}
|
||||
|
||||
func TestNewClientTransferTimeoutExceedsAPITimeout(t *testing.T) {
|
||||
c := NewClient("http://coord:8080", &StaticToken{token: "t"}, 30*time.Second)
|
||||
if c.apiClient.Timeout != 30*time.Second {
|
||||
t.Errorf("api timeout = %v, want 30s", c.apiClient.Timeout)
|
||||
}
|
||||
if c.dlClient.Timeout < 2*time.Minute {
|
||||
t.Errorf("transfer timeout = %v, want at least 2m", c.dlClient.Timeout)
|
||||
}
|
||||
short := NewClient("http://coord:8080", &StaticToken{token: "t"}, 3*time.Minute)
|
||||
if short.dlClient.Timeout != 12*time.Minute {
|
||||
t.Errorf("transfer timeout = %v, want 4x the api timeout", short.dlClient.Timeout)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user