1
0
mirror of https://github.com/rancher/os.git synced 2025-08-31 14:23:11 +00:00

Add http timeout when loading resource

This commit is contained in:
niusmallnan
2019-06-18 16:30:42 +08:00
committed by niusmallnan
parent 1ff4f6ebaa
commit 960d0d3bdb

View File

@@ -7,6 +7,7 @@ import (
"net/http"
"os"
"strings"
"time"
"github.com/rancher/os/config"
"github.com/rancher/os/pkg/log"
@@ -15,6 +16,10 @@ import (
composeConfig "github.com/docker/libcompose/config"
)
const (
defaultTimeout = 10 * time.Second
)
var (
ErrNoNetwork = errors.New("Networking not available to load resource")
ErrNotFound = errors.New("Failed to find resource")
@@ -110,7 +115,10 @@ func LoadFromNetwork(location string) ([]byte, error) {
var resp *http.Response
log.Debugf("LoadFromNetwork(%s)", location)
resp, err = http.Get(location)
netClient := &http.Client{
Timeout: defaultTimeout,
}
resp, err = netClient.Get(location)
log.Debugf("LoadFromNetwork(%s) returned %v, %v", location, resp, err)
if err == nil {
defer resp.Body.Close()