Skip to content

Commit dd27946

Browse files
committed
fix: cli binary download fixes
1 parent ea89cac commit dd27946

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

internal/update/github.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ const (
1919
releasesURL = "https://api.github.com/repos/pushchain/push-validator-cli/releases"
2020
releaseByTagURL = "https://api.github.com/repos/pushchain/push-validator-cli/releases/tags/%s"
2121

22-
httpTimeout = 30 * time.Second
22+
httpTimeout = 30 * time.Second // For API calls
23+
downloadTimeout = 10 * time.Minute // For binary downloads
2324
)
2425

2526
// FetchLatestRelease gets the latest release from GitHub

internal/update/updater.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ type HTTPDoer interface {
2424
type Updater struct {
2525
CurrentVersion string
2626
BinaryPath string // Path to current executable
27-
http HTTPDoer
27+
http HTTPDoer // For API calls (30s timeout)
28+
downloadHTTP HTTPDoer // For binary downloads (10min timeout)
2829
}
2930

3031
// New creates an Updater with the default HTTP client.
@@ -54,6 +55,7 @@ func NewWith(currentVersion string, h HTTPDoer) (*Updater, error) {
5455
CurrentVersion: currentVersion,
5556
BinaryPath: realPath,
5657
http: h,
58+
downloadHTTP: &http.Client{Timeout: downloadTimeout},
5759
}, nil
5860
}
5961

@@ -85,7 +87,12 @@ func (u *Updater) Download(asset *Asset, progress ProgressFunc) ([]byte, error)
8587
return nil, fmt.Errorf("failed to create download request: %w", err)
8688
}
8789

88-
resp, err := u.http.Do(req)
90+
// Use downloadHTTP for longer timeout, fall back to http if not set (e.g., in tests)
91+
client := u.downloadHTTP
92+
if client == nil {
93+
client = u.http
94+
}
95+
resp, err := client.Do(req)
8996
if err != nil {
9097
return nil, fmt.Errorf("failed to download: %w", err)
9198
}

0 commit comments

Comments
 (0)