Skip to content

Commit

Permalink
Add a timeout of 1 second to the update check command (#397)
Browse files Browse the repository at this point in the history
  • Loading branch information
marccampbell authored Jun 20, 2024
1 parent 760b1cc commit 2b06405
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.9.0
github.com/tj/go-spin v1.1.0
github.com/usrbinapp/usrbin-go v0.0.6-0.20240528182947-97f4d679ee25
github.com/usrbinapp/usrbin-go v0.0.6
golang.org/x/crypto v0.23.0
golang.org/x/term v0.20.0
gopkg.in/yaml.v3 v3.0.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,8 @@ github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8=
github.com/ulikunitz/xz v0.5.11/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/usrbinapp/usrbin-go v0.0.6-0.20240528182947-97f4d679ee25 h1:Mkrm0tKAMebM0G05L0khgw3xyLziJqy3/tGvfu+qPMs=
github.com/usrbinapp/usrbin-go v0.0.6-0.20240528182947-97f4d679ee25/go.mod h1:gDtvVf9mVkeVfWj4Oa4Ur4uZQOv9TXPfoKgwnLUbbic=
github.com/usrbinapp/usrbin-go v0.0.6 h1:B+LpBK1AT3SI6oH8BjR0z+rnYpVhpml2ZbN5wsXs7Gk=
github.com/usrbinapp/usrbin-go v0.0.6/go.mod h1:gDtvVf9mVkeVfWj4Oa4Ur4uZQOv9TXPfoKgwnLUbbic=
github.com/vbatts/tar-split v0.11.5 h1:3bHCTIheBm1qFTcgh9oPu+nNBtX+XJIupG/vacinCts=
github.com/vbatts/tar-split v0.11.5/go.mod h1:yZbwRsSeGjusneWgA781EKej9HF8vme8okylkAeNKLk=
github.com/vmware-tanzu/velero v1.13.2 h1:72Rw+11HJB6XUYfH9/M/jle6duSLyGhMisMMYFr/1qs=
Expand Down
4 changes: 2 additions & 2 deletions pkg/replicatedfile/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

const (
cacheTTLInHours = 4
cacheTTLInMinutes = 15

replicatedDir = ".replicated"
cacheFile = "cache.json"
Expand Down Expand Up @@ -53,7 +53,7 @@ func (c *cache) IsUpdateCheckerInfoExpired(currentVersion string) bool {
return true
}

if c.UpdateCheckerInfo.CheckedAt.Add(time.Duration(cacheTTLInHours) * time.Hour).Before(time.Now()) {
if c.UpdateCheckerInfo.CheckedAt.Add(time.Duration(cacheTTLInMinutes) * time.Minute).Before(time.Now()) {
return true
}

Expand Down
7 changes: 6 additions & 1 deletion pkg/version/usrbin.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package version

import "github.com/usrbinapp/usrbin-go"
import (
"time"

"github.com/usrbinapp/usrbin-go"
)

func NewUsrbinSDK(currentVersion string) (*usrbin.SDK, error) {
return usrbin.New(
currentVersion,
usrbin.UsingGitHubUpdateChecker("github.com/replicatedhq/replicated"),
usrbin.UsingHomebrewFormula("replicatedhq/replicated/cli"),
usrbin.UsingHttpTimeout(time.Second),
)
}
8 changes: 8 additions & 0 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"runtime"
"time"

"github.com/pkg/errors"
"github.com/replicatedhq/replicated/pkg/replicatedfile"
usrbingithub "github.com/usrbinapp/usrbin-go/pkg/github"
"github.com/usrbinapp/usrbin-go/pkg/updatechecker"
)

Expand Down Expand Up @@ -57,6 +59,12 @@ func initBuild() {

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

Expand Down

0 comments on commit 2b06405

Please sign in to comment.