Skip to content

Commit 073eb22

Browse files
authored
site: keep expired cache when background refresh failed (#100)
1 parent 0c64cfc commit 073eb22

1 file changed

Lines changed: 3 additions & 10 deletions

File tree

cmd/docsite/site.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,8 @@ func (fs *versionedFileSystemURL) OpenVersion(ctx context.Context, version strin
304304
if ok && time.Since(e.at) > fileSystemCacheTTL {
305305
log.Printf("# Cached site data for version %q expired after %s, refreshing in background", version, fileSystemCacheTTL)
306306
go e.refresh.Do(func() {
307-
ctx := context.Background() // use separate context because this runs in the background
308-
if _, err := fs.fetchAndCacheVersion(ctx, version); err != nil {
307+
if _, err := fs.fetchAndCacheVersion(version); err != nil {
309308
log.Printf("# Error refreshing site data for version %q in background: %s", version, err)
310-
// Cause the error to be user-visible on the next request so that external
311-
// monitoring tools will detect the problem (and the site won't silently remain
312-
// stale).
313-
fs.mu.Lock()
314-
delete(fs.cache, version)
315-
fs.mu.Unlock()
316309
return
317310
}
318311
})
@@ -321,10 +314,10 @@ func (fs *versionedFileSystemURL) OpenVersion(ctx context.Context, version strin
321314
if ok {
322315
return e.fs, nil
323316
}
324-
return fs.fetchAndCacheVersion(ctx, version)
317+
return fs.fetchAndCacheVersion(version)
325318
}
326319

327-
func (fs *versionedFileSystemURL) fetchAndCacheVersion(ctx context.Context, version string) (http.FileSystem, error) {
320+
func (fs *versionedFileSystemURL) fetchAndCacheVersion(version string) (http.FileSystem, error) {
328321
urlStr := fs.url
329322
if strings.Contains(urlStr, "$VERSION") && strings.Contains(urlStr, "github") && !strings.Contains(urlStr, "refs/heads/$VERSION") {
330323
return nil, fmt.Errorf("refusing to use insecure docsite configuration for multi-version-aware GitHub URLs: the URL pattern %q must include \"refs/heads/$VERSION\", not just \"$VERSION\" (see docsite README.md for more information)", urlStr)

0 commit comments

Comments
 (0)