fix: add timeout to http requests

this caused a serious delay on windows
This commit is contained in:
Jan De Dobbeleer 2020-12-31 09:39:02 +01:00 committed by Jan De Dobbeleer
parent 5fa33f4c4f
commit 4c771d3e15

View file

@ -13,6 +13,7 @@ import (
"path/filepath"
"runtime"
"strings"
"time"
"github.com/distatus/battery"
"github.com/shirou/gopsutil/host"
@ -264,7 +265,9 @@ func (env *environment) getShellName() string {
}
func (env *environment) doGet(url string) ([]byte, error) {
request, err := http.NewRequestWithContext(context.Background(), http.MethodGet, url, nil)
ctx, cncl := context.WithTimeout(context.Background(), time.Millisecond*20)
defer cncl()
request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return nil, err
}