Skip to content

Commit 2b06405

Browse files
authored
Add a timeout of 1 second to the update check command (#397)
1 parent 760b1cc commit 2b06405

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ require (
2323
github.com/spf13/pflag v1.0.5
2424
github.com/stretchr/testify v1.9.0
2525
github.com/tj/go-spin v1.1.0
26-
github.com/usrbinapp/usrbin-go v0.0.6-0.20240528182947-97f4d679ee25
26+
github.com/usrbinapp/usrbin-go v0.0.6
2727
golang.org/x/crypto v0.23.0
2828
golang.org/x/term v0.20.0
2929
gopkg.in/yaml.v3 v3.0.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,8 @@ github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8=
10621062
github.com/ulikunitz/xz v0.5.11/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
10631063
github.com/usrbinapp/usrbin-go v0.0.6-0.20240528182947-97f4d679ee25 h1:Mkrm0tKAMebM0G05L0khgw3xyLziJqy3/tGvfu+qPMs=
10641064
github.com/usrbinapp/usrbin-go v0.0.6-0.20240528182947-97f4d679ee25/go.mod h1:gDtvVf9mVkeVfWj4Oa4Ur4uZQOv9TXPfoKgwnLUbbic=
1065+
github.com/usrbinapp/usrbin-go v0.0.6 h1:B+LpBK1AT3SI6oH8BjR0z+rnYpVhpml2ZbN5wsXs7Gk=
1066+
github.com/usrbinapp/usrbin-go v0.0.6/go.mod h1:gDtvVf9mVkeVfWj4Oa4Ur4uZQOv9TXPfoKgwnLUbbic=
10651067
github.com/vbatts/tar-split v0.11.5 h1:3bHCTIheBm1qFTcgh9oPu+nNBtX+XJIupG/vacinCts=
10661068
github.com/vbatts/tar-split v0.11.5/go.mod h1:yZbwRsSeGjusneWgA781EKej9HF8vme8okylkAeNKLk=
10671069
github.com/vmware-tanzu/velero v1.13.2 h1:72Rw+11HJB6XUYfH9/M/jle6duSLyGhMisMMYFr/1qs=

pkg/replicatedfile/cache.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
const (
15-
cacheTTLInHours = 4
15+
cacheTTLInMinutes = 15
1616

1717
replicatedDir = ".replicated"
1818
cacheFile = "cache.json"
@@ -53,7 +53,7 @@ func (c *cache) IsUpdateCheckerInfoExpired(currentVersion string) bool {
5353
return true
5454
}
5555

56-
if c.UpdateCheckerInfo.CheckedAt.Add(time.Duration(cacheTTLInHours) * time.Hour).Before(time.Now()) {
56+
if c.UpdateCheckerInfo.CheckedAt.Add(time.Duration(cacheTTLInMinutes) * time.Minute).Before(time.Now()) {
5757
return true
5858
}
5959

pkg/version/usrbin.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package version
22

3-
import "github.com/usrbinapp/usrbin-go"
3+
import (
4+
"time"
5+
6+
"github.com/usrbinapp/usrbin-go"
7+
)
48

59
func NewUsrbinSDK(currentVersion string) (*usrbin.SDK, error) {
610
return usrbin.New(
711
currentVersion,
812
usrbin.UsingGitHubUpdateChecker("github.com/replicatedhq/replicated"),
913
usrbin.UsingHomebrewFormula("replicatedhq/replicated/cli"),
14+
usrbin.UsingHttpTimeout(time.Second),
1015
)
1116
}

pkg/version/version.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import (
66
"runtime"
77
"time"
88

9+
"github.com/pkg/errors"
910
"github.com/replicatedhq/replicated/pkg/replicatedfile"
11+
usrbingithub "github.com/usrbinapp/usrbin-go/pkg/github"
1012
"github.com/usrbinapp/usrbin-go/pkg/updatechecker"
1113
)
1214

@@ -57,6 +59,12 @@ func initBuild() {
5759

5860
build.UpdateInfo, err = usrbinsdk.GetUpdateInfo()
5961
if err != nil {
62+
if errors.Cause(err) == usrbingithub.ErrTimeoutExceeded {
63+
// i'm going to leave this println out for now because it could be really noisy
64+
// for someone with a slow connection
65+
// fmt.Fprintln(os.Stderr, "Unable to check for updates, timeout exceeded.")
66+
return
67+
}
6068
fmt.Fprintf(os.Stderr, "Error getting update info: %s", err)
6169
}
6270

0 commit comments

Comments
 (0)