From f3482d7cd8480d3aff06c1d5bee3a39f4e6b764a Mon Sep 17 00:00:00 2001 From: ginuerzh Date: Tue, 31 Jan 2023 18:05:36 +0800 Subject: [PATCH] fix nil route panic --- chain/router.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/chain/router.go b/chain/router.go index 95edad6..57e0ecc 100644 --- a/chain/router.go +++ b/chain/router.go @@ -204,7 +204,7 @@ func (r *Router) Bind(ctx context.Context, network, address string, opts ...Bind var route Route if r.options.Chain != nil { route = r.options.Chain.Route(ctx, network, address) - if len(route.Nodes()) == 0 { + if route == nil || len(route.Nodes()) == 0 { err = ErrEmptyRoute return } @@ -219,6 +219,9 @@ func (r *Router) Bind(ctx context.Context, network, address string, opts ...Bind r.options.Logger.Debugf("route(retry=%d) %s", i, buf.String()) } + if route == nil { + route = DefaultRoute + } ln, err = route.Bind(ctx, network, address, opts...) if err == nil { break