Skip to content

Commit 4c771d3

Browse files
fix: add timeout to http requests
this caused a serious delay on windows
1 parent 5fa33f4 commit 4c771d3

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/environment.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"path/filepath"
1414
"runtime"
1515
"strings"
16+
"time"
1617

1718
"github.com/distatus/battery"
1819
"github.com/shirou/gopsutil/host"
@@ -264,7 +265,9 @@ func (env *environment) getShellName() string {
264265
}
265266

266267
func (env *environment) doGet(url string) ([]byte, error) {
267-
request, err := http.NewRequestWithContext(context.Background(), http.MethodGet, url, nil)
268+
ctx, cncl := context.WithTimeout(context.Background(), time.Millisecond*20)
269+
defer cncl()
270+
request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
268271
if err != nil {
269272
return nil, err
270273
}

0 commit comments

Comments
 (0)