From 4c771d3e15ddf91b440c4aa13e705c765108b483 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Thu, 31 Dec 2020 09:39:02 +0100 Subject: [PATCH] fix: add timeout to http requests this caused a serious delay on windows --- src/environment.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/environment.go b/src/environment.go index 450886526a45..70330643f5f4 100644 --- a/src/environment.go +++ b/src/environment.go @@ -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 }