diff --git a/routing/dht/ext_test.go b/routing/dht/ext_test.go index e151af5d2462..ab756b5e4d6a 100644 --- a/routing/dht/ext_test.go +++ b/routing/dht/ext_test.go @@ -49,6 +49,10 @@ func TestGetFailures(t *testing.T) { // u.POut("Timout Test\n") ctx1, _ := context.WithTimeout(context.Background(), 200*time.Millisecond) if _, err := d.GetValue(ctx1, u.Key("test")); err != nil { + if merr, ok := err.(u.MultiErr); ok && len(merr) > 0 { + err = merr[0] + } + if err != context.DeadlineExceeded { t.Fatal("Got different error than we expected", err) } @@ -86,6 +90,9 @@ func TestGetFailures(t *testing.T) { ctx2, _ := context.WithTimeout(context.Background(), 20*time.Second) _, err = d.GetValue(ctx2, u.Key("test")) if err != nil { + if merr, ok := err.(u.MultiErr); ok && len(merr) > 0 { + err = merr[0] + } if err != routing.ErrNotFound { t.Fatalf("Expected ErrNotFound, got: %s", err) } @@ -202,6 +209,9 @@ func TestNotFound(t *testing.T) { v, err := d.GetValue(ctx, u.Key("hello")) log.Debugf("get value got %v", v) if err != nil { + if merr, ok := err.(u.MultiErr); ok && len(merr) > 0 { + err = merr[0] + } switch err { case routing.ErrNotFound: //Success! diff --git a/routing/dht/query.go b/routing/dht/query.go index 53c232323c77..0c69fb16f36c 100644 --- a/routing/dht/query.go +++ b/routing/dht/query.go @@ -62,7 +62,7 @@ type dhtQueryRunner struct { peersRemaining todoctr.Counter // peersToQuery + currently processing result *dhtQueryResult // query result - errs []error // result errors. maybe should be a map[peer.ID]error + errs u.MultiErr // result errors. maybe should be a map[peer.ID]error rateLimit chan struct{} // processing semaphore log eventlog.EventLogger @@ -122,8 +122,13 @@ func (r *dhtQueryRunner) Run(peers []peer.ID) (*dhtQueryResult, error) { r.RLock() defer r.RUnlock() - if len(r.errs) > 0 { - err = r.errs[0] // take the first? + err = routing.ErrNotFound + + // if every query to every peer failed, something must be very wrong. + if len(r.errs) > 0 && len(r.errs) == r.peersSeen.Size() { + err = r.errs + } else { + log.Infof("query errs: %s", r.errs) } case <-r.cg.Closed():