mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 07:36:27 -04:00
fix(updates): add timeout to HTTP requests in update checker
This commit is contained in:
parent
ddceff6962
commit
a986045904
|
|
@ -22,6 +22,10 @@ import (
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"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
|
// Updater checks for updates and does updates
|
||||||
type Updater struct {
|
type Updater struct {
|
||||||
*common.Common
|
*common.Common
|
||||||
|
|
@ -51,7 +55,7 @@ func (u *Updater) getLatestVersionNumber() (string, error) {
|
||||||
}
|
}
|
||||||
req.Header.Set("Accept", "application/json")
|
req.Header.Set("Accept", "application/json")
|
||||||
|
|
||||||
resp, err := http.DefaultClient.Do(req)
|
resp, err := httpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
@ -265,7 +269,7 @@ func (u *Updater) downloadAndInstall(rawUrl string) error {
|
||||||
defer out.Close()
|
defer out.Close()
|
||||||
|
|
||||||
// Get the data
|
// Get the data
|
||||||
resp, err := http.Get(rawUrl)
|
resp, err := httpClient.Get(rawUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -318,7 +322,7 @@ func (u *Updater) downloadAndInstall(rawUrl string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *Updater) verifyResourceFound(rawUrl string) bool {
|
func (u *Updater) verifyResourceFound(rawUrl string) bool {
|
||||||
resp, err := http.Head(rawUrl)
|
resp, err := httpClient.Head(rawUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue