Skip to content

Commit

Permalink
feat: change back-to-source timeout (dragonflyoss#1112)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi authored Mar 2, 2022
1 parent 3baf964 commit 373a037
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pkg/source/source_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ import (
logger "d7y.io/dragonfly/v2/internal/dflog"
)

var (
// Clinet back-to-source download timeout
contextTimeout = 30 * time.Second
)

var (
// ErrResourceNotReachable represents the url resource is a not reachable.
ErrResourceNotReachable = errors.New("resource is not reachable")
Expand Down Expand Up @@ -260,7 +265,7 @@ func GetContentLength(request *Request) (int64, error) {
return UnknownSourceFileLen, errors.Wrapf(ErrNoClientFound, "scheme: %s", request.URL.Scheme)
}
if _, ok := request.Context().Deadline(); !ok {
ctx, cancel := context.WithTimeout(context.Background(), 4*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), contextTimeout)
request = request.WithContext(ctx)
defer cancel()
}
Expand All @@ -273,7 +278,7 @@ func IsSupportRange(request *Request) (bool, error) {
return false, errors.Wrapf(ErrNoClientFound, "scheme: %s", request.URL.Scheme)
}
if _, ok := request.Context().Deadline(); !ok {
ctx, cancel := context.WithTimeout(context.Background(), 4*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), contextTimeout)
request = request.WithContext(ctx)
defer cancel()
}
Expand All @@ -289,7 +294,7 @@ func IsExpired(request *Request, info *ExpireInfo) (bool, error) {
return false, errors.Wrapf(ErrNoClientFound, "scheme: %s", request.URL.Scheme)
}
if _, ok := request.Context().Deadline(); !ok {
ctx, cancel := context.WithTimeout(context.Background(), 4*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), contextTimeout)
request = request.WithContext(ctx)
defer cancel()
}
Expand All @@ -302,7 +307,7 @@ func GetLastModified(request *Request) (int64, error) {
return -1, errors.Wrapf(ErrNoClientFound, "scheme: %s", request.URL.Scheme)
}
if _, ok := request.Context().Deadline(); !ok {
ctx, cancel := context.WithTimeout(context.Background(), 4*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), contextTimeout)
request = request.WithContext(ctx)
defer cancel()
}
Expand Down

0 comments on commit 373a037

Please sign in to comment.