TUN-3478: Increase download timeout to 60s

This commit is contained in:
cthuang 2020-10-22 10:38:18 +01:00
parent 04fa10ea7b
commit ea71b78e6d
2 changed files with 13 additions and 11 deletions

View File

@ -7,7 +7,6 @@ import (
"runtime" "runtime"
"strconv" "strconv"
"strings" "strings"
"time"
) )
// Options are the update options supported by the // Options are the update options supported by the
@ -53,7 +52,7 @@ func NewWorkersService(currentVersion, url, targetPath string, opts Options) Ser
// Check does a check in with the Workers API to get a new version update // Check does a check in with the Workers API to get a new version update
func (s *WorkersService) Check() (Version, error) { func (s *WorkersService) Check() (Version, error) {
client := &http.Client{ client := &http.Client{
Timeout: time.Second * 5, Timeout: clientTimeout,
} }
req, err := http.NewRequest(http.MethodGet, s.url, nil) req, err := http.NewRequest(http.MethodGet, s.url, nil)

View File

@ -18,20 +18,23 @@ import (
"time" "time"
) )
// stop the service const (
// rename cloudflared.exe to cloudflared.exe.old clientTimeout = time.Second * 60
// rename cloudflared.exe.new to cloudflared.exe // stop the service
// delete cloudflared.exe.old // rename cloudflared.exe to cloudflared.exe.old
// start the service // rename cloudflared.exe.new to cloudflared.exe
// delete the batch file // delete cloudflared.exe.old
const windowsUpdateCommandTemplate = `@echo off // start the service
// delete the batch file
windowsUpdateCommandTemplate = `@echo off
sc stop cloudflared >nul 2>&1 sc stop cloudflared >nul 2>&1
rename "{{.TargetPath}}" {{.OldName}} rename "{{.TargetPath}}" {{.OldName}}
rename "{{.NewPath}}" {{.BinaryName}} rename "{{.NewPath}}" {{.BinaryName}}
del "{{.OldPath}}" del "{{.OldPath}}"
sc start cloudflared >nul 2>&1 sc start cloudflared >nul 2>&1
del {{.BatchName}}` del {{.BatchName}}`
const batchFileName = "cfd_update.bat" batchFileName = "cfd_update.bat"
)
// Prepare some data to insert into the template. // Prepare some data to insert into the template.
type batchData struct { type batchData struct {
@ -118,7 +121,7 @@ func (v *WorkersVersion) String() string {
// download the file from the link in the json // download the file from the link in the json
func download(url, filepath string, isCompressed bool) error { func download(url, filepath string, isCompressed bool) error {
client := &http.Client{ client := &http.Client{
Timeout: time.Second * 5, Timeout: clientTimeout,
} }
resp, err := client.Get(url) resp, err := client.Get(url)