diff --git a/weed/operation/grpc_client.go b/weed/operation/grpc_client.go index ea7a82044..bf4d4bec3 100644 --- a/weed/operation/grpc_client.go +++ b/weed/operation/grpc_client.go @@ -44,7 +44,7 @@ func withMasterServerClient(masterServer string, grpcDialOption grpc.DialOption, masterGrpcAddress, parseErr := util.ParseServerToGrpcAddress(masterServer) if parseErr != nil { - return fmt.Errorf("failed to parse master grpc %v", masterServer) + return fmt.Errorf("failed to parse master grpc %v: %v", masterServer, parseErr) } return util.WithCachedGrpcClient(ctx, func(grpcConnection *grpc.ClientConn) error { diff --git a/weed/server/volume_grpc_client_to_master.go b/weed/server/volume_grpc_client_to_master.go index 7667ed363..a57ab48e7 100644 --- a/weed/server/volume_grpc_client_to_master.go +++ b/weed/server/volume_grpc_client_to_master.go @@ -34,7 +34,7 @@ func (vs *VolumeServer) heartbeat() { } masterGrpcAddress, parseErr := util.ParseServerToGrpcAddress(master) if parseErr != nil { - glog.V(0).Infof("failed to parse master grpc %v", masterGrpcAddress) + glog.V(0).Infof("failed to parse master grpc %v: %v", masterGrpcAddress, parseErr) continue } newLeader, err = vs.doHeartbeat(context.Background(), master, masterGrpcAddress, grpcDialOption, time.Duration(vs.pulseSeconds)*time.Second) diff --git a/weed/util/grpc_client_server.go b/weed/util/grpc_client_server.go index a2407eb13..31497ad35 100644 --- a/weed/util/grpc_client_server.go +++ b/weed/util/grpc_client_server.go @@ -88,19 +88,19 @@ func WithCachedGrpcClient(ctx context.Context, fn func(*grpc.ClientConn) error, } func ParseServerToGrpcAddress(server string) (serverGrpcAddress string, err error) { - hostnameAndPort := strings.Split(server, ":") - if len(hostnameAndPort) != 2 { - return "", fmt.Errorf("server should have hostname:port format: %v", hostnameAndPort) + colonIndex := strings.LastIndex(server, ":") + if colonIndex < 0 { + return "", fmt.Errorf("server should have hostname:port format: %v", server) } - port, parseErr := strconv.ParseUint(hostnameAndPort[1], 10, 64) + port, parseErr := strconv.ParseUint(server[colonIndex+1:], 10, 64) if parseErr != nil { return "", fmt.Errorf("server port parse error: %v", parseErr) } grpcPort := int(port) + 10000 - return fmt.Sprintf("%s:%d", hostnameAndPort[0], grpcPort), nil + return fmt.Sprintf("%s:%d", server[:colonIndex], grpcPort), nil } func ServerToGrpcAddress(server string) (serverGrpcAddress string) { diff --git a/weed/wdclient/masterclient.go b/weed/wdclient/masterclient.go index 7a0bc9181..fc8d3506b 100644 --- a/weed/wdclient/masterclient.go +++ b/weed/wdclient/masterclient.go @@ -103,7 +103,7 @@ func withMasterClient(ctx context.Context, master string, grpcDialOption grpc.Di masterGrpcAddress, parseErr := util.ParseServerToGrpcAddress(master) if parseErr != nil { - return fmt.Errorf("failed to parse master grpc %v", master) + return fmt.Errorf("failed to parse master grpc %v: %v", master, parseErr) } return util.WithCachedGrpcClient(ctx, func(grpcConnection *grpc.ClientConn) error {