diff --git a/pkg/common/chatrpcstart/start.go b/pkg/common/chatrpcstart/start.go index d3575d9e7..882487da5 100644 --- a/pkg/common/chatrpcstart/start.go +++ b/pkg/common/chatrpcstart/start.go @@ -35,11 +35,7 @@ import ( func Start(rpcPort int, rpcRegisterName string, prometheusPort int, rpcFn func(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error, options ...grpc.ServerOption) error { fmt.Println("start", rpcRegisterName, "server, port: ", rpcPort, "prometheusPort:", prometheusPort, ", OpenIM version: ", config.Version) - listener, err := net.Listen("tcp", net.JoinHostPort(network.GetListenIP(config.Config.Rpc.ListenIP), strconv.Itoa(rpcPort))) - if err != nil { - return err - } - defer listener.Close() + zkClient, err := openKeeper.NewClient(config.Config.Zookeeper.ZkAddr, config.Config.Zookeeper.Schema, openKeeper.WithFreq(time.Hour), openKeeper.WithUserNameAndPassword(config.Config.Zookeeper.Username, config.Config.Zookeeper.Password), openKeeper.WithRoundRobin(), openKeeper.WithTimeout(10), openKeeper.WithLogger(log.NewZkLogger())) @@ -50,7 +46,7 @@ func Start(rpcPort int, rpcRegisterName string, prometheusPort int, rpcFn func(c zkClient.AddOption(chatMw.AddUserType(), mw.GrpcClient(), grpc.WithTransportCredentials(insecure.NewCredentials())) registerIP, err := network.GetRpcRegisterIP(config.Config.Rpc.RegisterIP) if err != nil { - return err + return utils.Wrap1(err) } srv := grpc.NewServer(append(options, mw.GrpcServer())...) defer srv.GracefulStop() @@ -62,5 +58,10 @@ func Start(rpcPort int, rpcRegisterName string, prometheusPort int, rpcFn func(c if err != nil { return utils.Wrap1(err) } + listener, err := net.Listen("tcp", net.JoinHostPort(network.GetListenIP(config.Config.Rpc.ListenIP), strconv.Itoa(rpcPort))) + if err != nil { + return utils.Wrap1(err) + } + defer listener.Close() return utils.Wrap1(srv.Serve(listener)) }