Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions pkg/updates/updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import (
"github.com/jesseduffield/lazygit/pkg/utils"
)

// httpClient is used for all update-related HTTP requests. A 30-second timeout
// prevents the update checker from stalling indefinitely if GitHub is slow or unreachable.
var httpClient = &http.Client{Timeout: 30 * time.Second}

// Updater checks for updates and does updates
type Updater struct {
*common.Common
Expand Down Expand Up @@ -51,7 +55,7 @@ func (u *Updater) getLatestVersionNumber() (string, error) {
}
req.Header.Set("Accept", "application/json")

resp, err := http.DefaultClient.Do(req)
resp, err := httpClient.Do(req)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -265,7 +269,7 @@ func (u *Updater) downloadAndInstall(rawUrl string) error {
defer out.Close()

// Get the data
resp, err := http.Get(rawUrl)
resp, err := httpClient.Get(rawUrl)
if err != nil {
return err
}
Expand Down Expand Up @@ -318,7 +322,7 @@ func (u *Updater) downloadAndInstall(rawUrl string) error {
}

func (u *Updater) verifyResourceFound(rawUrl string) bool {
resp, err := http.Head(rawUrl)
resp, err := httpClient.Head(rawUrl)
if err != nil {
return false
}
Expand Down