Skip to content

Commit

Permalink
Remove the retries on error in remote resources.Get
Browse files Browse the repository at this point in the history
Fixes #9271
See  #9259
  • Loading branch information
bep committed Dec 10, 2021
1 parent e4d6ec9 commit 3bc6830
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 31 deletions.
26 changes: 4 additions & 22 deletions cache/filecache/filecache.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ type Cache struct {
// 0 is effectively turning this cache off.
maxAge time.Duration

// Number of retries on create error.
retries int

// When set, we just remove this entire root directory on expiration.
pruneAllRootDir string

Expand Down Expand Up @@ -87,12 +84,11 @@ type ItemInfo struct {
}

// NewCache creates a new file cache with the given filesystem and max age.
func NewCache(fs afero.Fs, maxAge time.Duration, retries int, pruneAllRootDir string) *Cache {
func NewCache(fs afero.Fs, maxAge time.Duration, pruneAllRootDir string) *Cache {
return &Cache{
Fs: fs,
nlocker: &lockTracker{Locker: locker.NewLocker(), seen: make(map[string]struct{})},
maxAge: maxAge,
retries: retries,
pruneAllRootDir: pruneAllRootDir,
}
}
Expand Down Expand Up @@ -184,14 +180,7 @@ func (c *Cache) GetOrCreate(id string, create func() (io.ReadCloser, error)) (It
err error
)

for i := -1; i < c.retries; i++ {
r, err = create()
if err == nil || c.retries == 0 {
break
}
time.Sleep(1 * time.Second)
}

r, err = create()
if err != nil {
return info, nil, err
}
Expand Down Expand Up @@ -227,14 +216,7 @@ func (c *Cache) GetOrCreateBytes(id string, create func() ([]byte, error)) (Item
err error
)

for i := -1; i < c.retries; i++ {
b, err = create()
if err == nil || c.retries == 0 {
break
}
time.Sleep(1 * time.Second)
}

b, err = create()
if err != nil {
return info, nil, err
}
Expand Down Expand Up @@ -388,7 +370,7 @@ func NewCaches(p *helpers.PathSpec) (Caches, error) {
pruneAllRootDir = "pkg"
}

m[k] = NewCache(bfs, v.MaxAge, v.retries, pruneAllRootDir)
m[k] = NewCache(bfs, v.MaxAge, pruneAllRootDir)
}

return m, nil
Expand Down
9 changes: 2 additions & 7 deletions cache/filecache/filecache_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ var defaultCacheConfigs = Configs{
Dir: resourcesGenDir,
},
cacheKeyGetResource: Config{
MaxAge: -1, // Never expire
Dir: cacheDirProject,
retries: 3, // Retries on error getting the remote resource.
MaxAge: -1, // Never expire
Dir: cacheDirProject,
},
}

Expand All @@ -91,10 +90,6 @@ type Config struct {
// Will resources/_gen will get its own composite filesystem that
// also checks any theme.
isResourceDir bool

// Number of retries when errors occurs when creating the element,
// only used for remote resources.
retries int
}

// GetJSONCache gets the file cache for getJSON.
Expand Down
2 changes: 1 addition & 1 deletion cache/filecache/filecache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func TestFileCacheReadOrCreateErrorInRead(t *testing.T) {
}
}

cache := NewCache(afero.NewMemMapFs(), 100*time.Hour, 0, "")
cache := NewCache(afero.NewMemMapFs(), 100*time.Hour, "")

const id = "a32"

Expand Down
2 changes: 1 addition & 1 deletion tpl/data/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestScpGetRemote(t *testing.T) {
t.Parallel()
c := qt.New(t)
fs := new(afero.MemMapFs)
cache := filecache.NewCache(fs, 100, 0, "")
cache := filecache.NewCache(fs, 100, "")

tests := []struct {
path string
Expand Down

0 comments on commit 3bc6830

Please sign in to comment.