Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configurable Stash timeout #2021

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/proxy/actions/app_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func addProxyRoutes(
if err != nil {
return err
}
st := stash.New(mf, s, indexer, stash.WithPool(c.GoGetWorkers), withSingleFlight)
st := stash.New(mf, s, indexer, c.TimeoutDuration(), stash.WithPool(c.GoGetWorkers), withSingleFlight)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are reusing the ATHENS_TIMEOUT variable, I'd suggest documenting that it now also serves this purpose.

Also, I don't know if there is a direct correlation between the timeout users might want to use for the VCS lister and for the stash. I'll let the others decide on whether it should be separate timeouts or not.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for comment! Also want to mention, that stasher uses storage backend for uploading files, and for some providers (for example s3) it uses ATHENS_TIMEOUT as timeout for upload operations. It was a reason for reusing ATHENS_TIMEOUT instead of adding separete var, as for me it would be more clear behaviour.


df, err := mode.NewFile(c.DownloadMode, c.DownloadURL)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/download/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func getDP(t *testing.T) Protocol {
if err != nil {
t.Fatal(err)
}
st := stash.New(mf, s, nop.New())
st := stash.New(mf, s, nop.New(), 10*time.Minute)
return New(&Opts{
Storage: s,
Stasher: st,
Expand Down Expand Up @@ -382,7 +382,7 @@ func TestDownloadProtocol(t *testing.T) {
t.Fatal(err)
}
mp := &mockFetcher{}
st := stash.New(mp, s, nop.New())
st := stash.New(mp, s, nop.New(), 10*time.Minute)
dp := New(&Opts{s, st, nil, nil, Strict})
ctx := context.Background()

Expand Down Expand Up @@ -434,7 +434,7 @@ func TestDownloadProtocolWhenFetchFails(t *testing.T) {
t.Fatal(err)
}
mp := &notFoundFetcher{}
st := stash.New(mp, s, nop.New())
st := stash.New(mp, s, nop.New(), 10*time.Minute)
dp := New(&Opts{s, st, nil, nil, Strict})
ctx := context.Background()
_, err = dp.GoMod(ctx, fakeMod.mod, fakeMod.ver)
Expand Down
7 changes: 4 additions & 3 deletions pkg/stash/stasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ type Wrapper func(Stasher) Stasher
// New returns a plain stasher that takes
// a module from a download.Protocol and
// stashes it into a backend.Storage.
func New(f module.Fetcher, s storage.Backend, indexer index.Indexer, wrappers ...Wrapper) Stasher {
var st Stasher = &stasher{f, s, storage.WithChecker(s), indexer}
func New(f module.Fetcher, s storage.Backend, indexer index.Indexer, timeout time.Duration, wrappers ...Wrapper) Stasher {
var st Stasher = &stasher{f, s, storage.WithChecker(s), indexer, timeout}
for _, w := range wrappers {
st = w(st)
}
Expand All @@ -42,6 +42,7 @@ type stasher struct {
storage storage.Backend
checker storage.Checker
indexer index.Indexer
timeout time.Duration
}

func (s *stasher) Stash(ctx context.Context, mod, ver string) (string, error) {
Expand All @@ -52,7 +53,7 @@ func (s *stasher) Stash(ctx context.Context, mod, ver string) (string, error) {

// create a new context that ditches whatever deadline the caller passed
// but keep the tracing info so that we can properly trace the whole thing.
ctx, cancel := context.WithTimeout(trace.NewContext(context.Background(), span), time.Minute*10)
ctx, cancel := context.WithTimeout(trace.NewContext(context.Background(), span), s.timeout)
defer cancel()
v, err := s.fetchModule(ctx, mod, ver)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion pkg/stash/stasher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"strings"
"testing"
"time"

"github.com/gomods/athens/pkg/index/nop"
"github.com/gomods/athens/pkg/storage"
Expand Down Expand Up @@ -54,7 +55,7 @@ func TestStash(t *testing.T) {
var mf mockFetcher
mf.ver = testCase.modVer

s := New(&mf, &ms, nop.New())
s := New(&mf, &ms, nop.New(), 10*time.Minute)
newVersion, err := s.Stash(context.Background(), "module", testCase.ver)
if err != nil {
t.Fatal(err)
Expand Down
Loading