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"
) )
const (
clientTimeout = time.Second * 60
// stop the service // stop the service
// rename cloudflared.exe to cloudflared.exe.old // rename cloudflared.exe to cloudflared.exe.old
// rename cloudflared.exe.new to cloudflared.exe // rename cloudflared.exe.new to cloudflared.exe
// delete cloudflared.exe.old // delete cloudflared.exe.old
// start the service // start the service
// delete the batch file // delete the batch file
const windowsUpdateCommandTemplate = `@echo off 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)