feat: change back-to-source timeout (#1112)
Signed-off-by: Gaius <gaius.qi@gmail.com>
This commit is contained in:
parent
0326f781f4
commit
f16c5592ab
|
|
@ -31,6 +31,11 @@ import (
|
||||||
logger "d7y.io/dragonfly/v2/internal/dflog"
|
logger "d7y.io/dragonfly/v2/internal/dflog"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// Clinet back-to-source download timeout
|
||||||
|
contextTimeout = 30 * time.Second
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// ErrResourceNotReachable represents the url resource is a not reachable.
|
// ErrResourceNotReachable represents the url resource is a not reachable.
|
||||||
ErrResourceNotReachable = errors.New("resource is not reachable")
|
ErrResourceNotReachable = errors.New("resource is not reachable")
|
||||||
|
|
@ -260,7 +265,7 @@ func GetContentLength(request *Request) (int64, error) {
|
||||||
return UnknownSourceFileLen, errors.Wrapf(ErrNoClientFound, "scheme: %s", request.URL.Scheme)
|
return UnknownSourceFileLen, errors.Wrapf(ErrNoClientFound, "scheme: %s", request.URL.Scheme)
|
||||||
}
|
}
|
||||||
if _, ok := request.Context().Deadline(); !ok {
|
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)
|
request = request.WithContext(ctx)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
}
|
}
|
||||||
|
|
@ -273,7 +278,7 @@ func IsSupportRange(request *Request) (bool, error) {
|
||||||
return false, errors.Wrapf(ErrNoClientFound, "scheme: %s", request.URL.Scheme)
|
return false, errors.Wrapf(ErrNoClientFound, "scheme: %s", request.URL.Scheme)
|
||||||
}
|
}
|
||||||
if _, ok := request.Context().Deadline(); !ok {
|
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)
|
request = request.WithContext(ctx)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
}
|
}
|
||||||
|
|
@ -289,7 +294,7 @@ func IsExpired(request *Request, info *ExpireInfo) (bool, error) {
|
||||||
return false, errors.Wrapf(ErrNoClientFound, "scheme: %s", request.URL.Scheme)
|
return false, errors.Wrapf(ErrNoClientFound, "scheme: %s", request.URL.Scheme)
|
||||||
}
|
}
|
||||||
if _, ok := request.Context().Deadline(); !ok {
|
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)
|
request = request.WithContext(ctx)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
}
|
}
|
||||||
|
|
@ -302,7 +307,7 @@ func GetLastModified(request *Request) (int64, error) {
|
||||||
return -1, errors.Wrapf(ErrNoClientFound, "scheme: %s", request.URL.Scheme)
|
return -1, errors.Wrapf(ErrNoClientFound, "scheme: %s", request.URL.Scheme)
|
||||||
}
|
}
|
||||||
if _, ok := request.Context().Deadline(); !ok {
|
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)
|
request = request.WithContext(ctx)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue