Skip to content

Commit

Permalink
fix: contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
zelig committed Jan 23, 2024
1 parent 606f2a8 commit 6d4f2cb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
4 changes: 4 additions & 0 deletions pkg/file/joiner/joiner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/ethersphere/bee/pkg/swarm"
"github.com/ethersphere/bee/pkg/util/testutil"
"github.com/ethersphere/bee/pkg/util/testutil/pseudorand"
"github.com/ethersphere/bee/pkg/util/testutil/racedetection"
"gitlab.com/nolash/go-mockbytes"
"golang.org/x/sync/errgroup"
)
Expand Down Expand Up @@ -1242,6 +1243,9 @@ func TestJoinerRedundancyMultilevel(t *testing.T) {
canReadRange := func(t *testing.T, s getter.Strategy, fallback bool, levels int, canRead bool) {
ctx := context.Background()
strategyTimeout := 100 * time.Millisecond
if racedetection.IsOn() {
strategyTimeout *= 2
}
ctx = getter.SetConfigInContext(ctx, s, fallback, (2 * strategyTimeout).String(), strategyTimeout.String())
ctx, cancel := context.WithTimeout(ctx, time.Duration(levels*3+1)*strategyTimeout)
defer cancel()
Expand Down
14 changes: 2 additions & 12 deletions pkg/file/redundancy/getter/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"io"
"sync"
"sync/atomic"
"time"

"github.com/ethersphere/bee/pkg/storage"
"github.com/ethersphere/bee/pkg/swarm"
Expand Down Expand Up @@ -76,7 +75,7 @@ func New(addrs []swarm.Address, shardCnt int, g storage.Getter, p storage.Putter
if !conf.Strict || conf.Strategy != NONE {
rsg.wg.Add(1)
go func() {
rsg.prefetch(ctx)
rsg.err = rsg.prefetch(ctx)
rsg.wg.Done()
}()
}
Expand All @@ -100,16 +99,7 @@ func (g *decoder) Get(ctx context.Context, addr swarm.Address) (swarm.Chunk, err
select {
case <-g.waits[i]:
case <-ctx.Done():
select {
case <-g.ready:
select {
case <-g.waits[i]:
case <-time.After(1 * time.Second):
return nil, ctx.Err()
}
default:
return nil, ctx.Err()
}
return nil, ctx.Err()
}
return swarm.NewChunk(addr, g.getData(i)), nil
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/file/redundancy/getter/strategies.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ func SetConfigInContext(ctx context.Context, s Strategy, fallbackmode bool, fetc
return ctx
}

func (g *decoder) prefetch(ctx context.Context) {
func (g *decoder) prefetch(ctx context.Context) error {
if g.config.Strict && g.config.Strategy == NONE {
return
return nil
}
defer g.remove()
var cancels []func()
Expand Down Expand Up @@ -172,7 +172,7 @@ func (g *decoder) prefetch(ctx context.Context) {
}
}

g.err = err
return err
}

// prefetch launches the retrieval of chunks based on the strategy
Expand Down

0 comments on commit 6d4f2cb

Please sign in to comment.