diff --git a/cluster/cluster.go b/cluster/cluster.go index b96fa1d..2863349 100644 --- a/cluster/cluster.go +++ b/cluster/cluster.go @@ -500,7 +500,7 @@ func GetNodeName(nodeid int) string { } func DynamicCall(address string, serviceMethod string, args interface{}, reply interface{}) error { - rpcClient, err := rpc.Dial("tcp", address) + rpcClient, err := rpc.DialTimeOut("tcp", address, time.Second*1) if err != nil { return err } diff --git a/rpc/client.go b/rpc/client.go index 7825359..9a6137f 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -291,7 +291,16 @@ func Dial(network, address string) (*Client, error) { } tcpconn, _ := conn.(*net.TCPConn) tcpconn.SetNoDelay(true) + return NewClient(conn), nil +} +func DialTimeOut(network, address string, timeout time.Duration) (*Client, error) { + conn, err := net.DialTimeout(network, address, timeout) + if err != nil { + return nil, err + } + tcpconn, _ := conn.(*net.TCPConn) + tcpconn.SetNoDelay(true) return NewClient(conn), nil }