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

fix(share/getters): set minTimeout #3591

Merged
merged 2 commits into from
Aug 6, 2024
Merged
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
11 changes: 10 additions & 1 deletion share/getters/cascade.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package getters
import (
"context"
"errors"
"time"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
Expand Down Expand Up @@ -119,13 +120,21 @@ func cascadeGetters[V any](
}
}()

minTimeout := time.Duration(0)
_, ok := ctx.Deadline()
if !ok {
// in this case minTimeout will be applied for all getters,so each of them
// will have 1 minute timeout.
minTimeout = time.Minute
}
walldiss marked this conversation as resolved.
Show resolved Hide resolved

for i, getter := range getters {
log.Debugf("cascade: launching getter #%d", i)
span.AddEvent("getter launched", trace.WithAttributes(attribute.Int("getter_idx", i)))

// we split the timeout between left getters
// once async cascadegetter is implemented, we can remove this
getCtx, cancel := ctxWithSplitTimeout(ctx, len(getters)-i, 0)
getCtx, cancel := ctxWithSplitTimeout(ctx, len(getters)-i, minTimeout)
val, getErr := get(getCtx, getter)
cancel()
if getErr == nil {
Expand Down
13 changes: 13 additions & 0 deletions share/getters/cascade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ func TestCascade(t *testing.T) {
return nil, ctx.Err()
}).AnyTimes()

stuckGetter := mocks.NewMockGetter(ctrl)
stuckGetter.EXPECT().GetEDS(gomock.Any(), gomock.Any()).
DoAndReturn(func(ctx context.Context, _ *header.ExtendedHeader) (*rsmt2d.ExtendedDataSquare, error) {
<-ctx.Done()
return nil, ctx.Err()
}).AnyTimes()

get := func(ctx context.Context, get share.Getter) (*rsmt2d.ExtendedDataSquare, error) {
return get.GetEDS(ctx, nil)
}
Expand Down Expand Up @@ -116,4 +123,10 @@ func TestCascade(t *testing.T) {
_, err := cascadeGetters(ctx, getters, get)
assert.NoError(t, err)
})

t.Run("Stuck getter", func(t *testing.T) {
getters := []share.Getter{stuckGetter, successGetter}
_, err := cascadeGetters(ctx, getters, get)
assert.NoError(t, err)
})
}
Loading