Commit 2c5fe90b authored by Janoš Guljaš's avatar Janoš Guljaš Committed by GitHub

retrieval: return chunk not found if max peers reached (#524)

parent 5ada5bcd
...@@ -7,9 +7,9 @@ package retrieval ...@@ -7,9 +7,9 @@ package retrieval
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/ethersphere/bee/pkg/accounting"
"time" "time"
"github.com/ethersphere/bee/pkg/accounting"
"github.com/ethersphere/bee/pkg/logging" "github.com/ethersphere/bee/pkg/logging"
"github.com/ethersphere/bee/pkg/p2p" "github.com/ethersphere/bee/pkg/p2p"
"github.com/ethersphere/bee/pkg/p2p/protobuf" "github.com/ethersphere/bee/pkg/p2p/protobuf"
...@@ -85,11 +85,11 @@ const ( ...@@ -85,11 +85,11 @@ const (
retrieveChunkTimeout = 10 * time.Second retrieveChunkTimeout = 10 * time.Second
) )
func (s *Service) RetrieveChunk(ctx context.Context, addr swarm.Address) (chunk swarm.Chunk, err error) { func (s *Service) RetrieveChunk(ctx context.Context, addr swarm.Address) (swarm.Chunk, error) {
ctx, cancel := context.WithTimeout(ctx, maxPeers*retrieveChunkTimeout) ctx, cancel := context.WithTimeout(ctx, maxPeers*retrieveChunkTimeout)
defer cancel() defer cancel()
v, err, _ := s.singleflight.Do(addr.String(), func() (v interface{}, err error) { v, err, _ := s.singleflight.Do(addr.String(), func() (interface{}, error) {
var skipPeers []swarm.Address var skipPeers []swarm.Address
for i := 0; i < maxPeers; i++ { for i := 0; i < maxPeers; i++ {
var peer swarm.Address var peer swarm.Address
...@@ -105,7 +105,8 @@ func (s *Service) RetrieveChunk(ctx context.Context, addr swarm.Address) (chunk ...@@ -105,7 +105,8 @@ func (s *Service) RetrieveChunk(ctx context.Context, addr swarm.Address) (chunk
s.logger.Tracef("retrieval: got chunk %s from peer %s", addr, peer) s.logger.Tracef("retrieval: got chunk %s from peer %s", addr, peer)
return chunk, nil return chunk, nil
} }
return nil, err s.logger.Debugf("retrieval: failed to get chunk %s: reached max peers of %v", addr, maxPeers)
return nil, storage.ErrNotFound
}) })
if err != nil { if err != nil {
return nil, err return nil, err
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment