From 6d4f2cbc7bbd2b4c3b8b8ad8438e43eefb146a4a Mon Sep 17 00:00:00 2001 From: zelig Date: Tue, 23 Jan 2024 17:05:01 +0100 Subject: [PATCH] fix: contexts --- pkg/file/joiner/joiner_test.go | 4 ++++ pkg/file/redundancy/getter/getter.go | 14 ++------------ pkg/file/redundancy/getter/strategies.go | 6 +++--- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/pkg/file/joiner/joiner_test.go b/pkg/file/joiner/joiner_test.go index 154a5978dd0..21a674f10b5 100644 --- a/pkg/file/joiner/joiner_test.go +++ b/pkg/file/joiner/joiner_test.go @@ -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" ) @@ -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() diff --git a/pkg/file/redundancy/getter/getter.go b/pkg/file/redundancy/getter/getter.go index 9f64674ed28..4e8da1b6390 100644 --- a/pkg/file/redundancy/getter/getter.go +++ b/pkg/file/redundancy/getter/getter.go @@ -9,7 +9,6 @@ import ( "io" "sync" "sync/atomic" - "time" "github.com/ethersphere/bee/pkg/storage" "github.com/ethersphere/bee/pkg/swarm" @@ -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() }() } @@ -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 } diff --git a/pkg/file/redundancy/getter/strategies.go b/pkg/file/redundancy/getter/strategies.go index dc16be174ac..bb5188e9cc2 100644 --- a/pkg/file/redundancy/getter/strategies.go +++ b/pkg/file/redundancy/getter/strategies.go @@ -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() @@ -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