Skip to content

Commit

Permalink
add more clear error when rpc service is not started
Browse files Browse the repository at this point in the history
  • Loading branch information
kevwan committed Sep 23, 2020
1 parent 17a0908 commit 0dd8e27
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions zrpc/internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package internal

import (
"context"
"errors"
"fmt"
"strings"
"time"

"github.com/tal-tech/go-zero/zrpc/internal/balancer/p2c"
Expand All @@ -11,7 +13,10 @@ import (
"google.golang.org/grpc"
)

const dialTimeout = time.Second * 3
const (
dialTimeout = time.Second * 3
separator = '/'
)

func init() {
resolver.RegisterResolver()
Expand Down Expand Up @@ -83,7 +88,16 @@ func dial(server string, opts ...ClientOption) (*grpc.ClientConn, error) {
defer cancel()
conn, err := grpc.DialContext(timeCtx, server, options...)
if err != nil {
return nil, fmt.Errorf("rpc dial: %s, error: %s", server, err.Error())
service := server
if errors.Is(err, context.DeadlineExceeded) {
pos := strings.LastIndexByte(server, separator)
// len(server) - 1 is the index of last char
if 0 < pos && pos < len(server)-1 {
service = server[pos+1:]
}
}
return nil, fmt.Errorf("rpc dial: %s, error: %s, make sure rpc service %q is alread started",
server, err.Error(), service)
}

return conn, nil
Expand Down

0 comments on commit 0dd8e27

Please sign in to comment.