From 2933804bd93e1e2617fdc2674bd85262f7bfd520 Mon Sep 17 00:00:00 2001 From: Bob Stasyszyn Date: Tue, 15 May 2018 14:30:55 -0400 Subject: [PATCH] [FAB-10079] Use successful response from discovery Loop through all responses and choose the first response without error. Change-Id: I5886fbaba3151710be0f058bc9fdbd7c76b459c2 Signed-off-by: Bob Stasyszyn --- .../discovery/dynamicdiscovery/chservice.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/pkg/client/common/discovery/dynamicdiscovery/chservice.go b/pkg/client/common/discovery/dynamicdiscovery/chservice.go index 21ed5c8e02..efe436fb6d 100644 --- a/pkg/client/common/discovery/dynamicdiscovery/chservice.go +++ b/pkg/client/common/discovery/dynamicdiscovery/chservice.go @@ -93,12 +93,17 @@ func (s *channelService) evaluate(ctx contextAPI.Channel, responses []fabdiscove // TODO: In a future patch: // - validate the signatures in the responses // - ensure N responses match according to the policy - // For now just pick the first response - response := responses[0] - endpoints, err := response.ForChannel(ctx.ChannelID()).Peers() - if err != nil { - return nil, errors.Wrapf(err, "error getting peers from discovery response") + // For now just pick the first successful response + + var lastErr error + for _, response := range responses { + endpoints, err := response.ForChannel(ctx.ChannelID()).Peers() + if err != nil { + lastErr = errors.Wrapf(err, "error getting peers from discovery response") + logger.Warn(lastErr.Error()) + continue + } + return asPeers(ctx, endpoints), nil } - - return asPeers(ctx, endpoints), nil + return nil, lastErr }