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(steward): swallow ErrWantSelf #1980

Merged
merged 1 commit into from
Jun 4, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion pkg/steward/steward.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ package steward

import (
"context"
"errors"
"fmt"

"github.com/ethersphere/bee/pkg/pushsync"
"github.com/ethersphere/bee/pkg/storage"
"github.com/ethersphere/bee/pkg/swarm"
"github.com/ethersphere/bee/pkg/topology"
"github.com/ethersphere/bee/pkg/traversal"
"golang.org/x/sync/errgroup"
)
Expand Down Expand Up @@ -55,7 +57,10 @@ func (s *steward) Reupload(ctx context.Context, root swarm.Address) error {
defer func() { <-sem }()
_, err := s.push.PushChunkToClosest(ctx, c)
if err != nil {
return err
if !errors.Is(err, topology.ErrWantSelf) {
return err
}
// swallow the error in case we are the closest node
}
return nil
})
Expand Down
35 changes: 35 additions & 0 deletions pkg/steward/steward_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/ethersphere/bee/pkg/storage"
"github.com/ethersphere/bee/pkg/storage/mock"
"github.com/ethersphere/bee/pkg/swarm"
"github.com/ethersphere/bee/pkg/topology"
"github.com/ethersphere/bee/pkg/traversal"
)

Expand Down Expand Up @@ -69,6 +70,40 @@ func TestSteward(t *testing.T) {
}
}

func TestSteward_ErrWantSelf(t *testing.T) {
var (
ctx = context.Background()
chunks = 10
data = make([]byte, chunks*4096)
store = mock.NewStorer()
traverser = traversal.New(store)
fn = func(_ context.Context, ch swarm.Chunk) (*pushsync.Receipt, error) {
return nil, topology.ErrWantSelf
}
ps = psmock.New(fn)
s = steward.New(store, traverser, ps)
)
n, err := rand.Read(data)
if n != cap(data) {
t.Fatal("short read")
}
if err != nil {
t.Fatal(err)
}

l := &loggingStore{Storer: store}
pipe := builder.NewPipelineBuilder(ctx, l, storage.ModePutUpload, false)
addr, err := builder.FeedPipeline(ctx, pipe, bytes.NewReader(data))
if err != nil {
t.Fatal(err)
}

err = s.Reupload(ctx, addr)
if err != nil {
t.Fatal(err)
}
}

type loggingStore struct {
storage.Storer
addrs []swarm.Address
Expand Down