Skip to content

Commit

Permalink
fix: add timeout to http requests
Browse files Browse the repository at this point in the history
this caused a serious delay on windows
  • Loading branch information
JanDeDobbeleer committed Dec 31, 2020
1 parent 5fa33f4 commit 4c771d3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/environment.go
Expand Up @@ -13,6 +13,7 @@ import (
"path/filepath"
"runtime"
"strings"
"time"

"github.com/distatus/battery"
"github.com/shirou/gopsutil/host"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 4c771d3

Please sign in to comment.