From 27a8866dccf2053e450791f7a439442526df9f5b Mon Sep 17 00:00:00 2001 From: yuqitao Date: Tue, 16 Apr 2019 22:23:28 +0800 Subject: [PATCH] `FailFast(false)`, return helpful error message when context is time out --- picker_wrapper.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/picker_wrapper.go b/picker_wrapper.go index f9625496c403..0d0db419ef50 100644 --- a/picker_wrapper.go +++ b/picker_wrapper.go @@ -120,6 +120,14 @@ func (bp *pickerWrapper) pick(ctx context.Context, failfast bool, opts balancer. bp.mu.Unlock() select { case <-ctx.Done(): + if bp.connectionError() != nil { + switch ctx.Err() { + case context.DeadlineExceeded: + return nil, nil, status.Errorf(codes.DeadlineExceeded, "latest connection error: %v", bp.connectionError()) + case context.Canceled: + return nil, nil, status.Errorf(codes.Canceled, "latest connection error: %v", bp.connectionError()) + } + } return nil, nil, ctx.Err() case <-ch: }