Skip to content

Commit 3b606ea

Browse files
sudo-sturbiajba
authored andcommitted
internal/proxydatasource: cache fetching errors
Update getModule to correctly cache fetching errors. Don't cache context cancellation errors, to give the server a chance to retry fetching a module if sudden interrupts occur. Fixes golang/go#42886 Change-Id: I0fdcbcbb3c899c90dff745a69703a401981b98a7 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/274152 Reviewed-by: Julie Qiu <[email protected]> Reviewed-by: Jonathan Amsterdam <[email protected]> Trust: Julie Qiu <[email protected]> Run-TryBot: Julie Qiu <[email protected]>
1 parent cc648b7 commit 3b606ea

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

internal/proxydatasource/datasource.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,14 @@ func (ds *DataSource) getModule(ctx context.Context, modulePath, version string)
9999
m.RemoveNonRedistributableData()
100100
}
101101
}
102-
ds.versionCache[key] = &versionEntry{module: m, err: err}
102+
103103
if res.Error != nil {
104+
if !errors.Is(ctx.Err(), context.Canceled) {
105+
ds.versionCache[key] = &versionEntry{module: m, err: res.Error}
106+
}
104107
return nil, res.Error
105108
}
109+
ds.versionCache[key] = &versionEntry{module: m, err: err}
106110

107111
// Since we hold the lock and missed the cache, we can assume that we have
108112
// never seen this module version. Therefore the following insert-and-sort

0 commit comments

Comments
 (0)