diff --git a/rpc/rpc_client.go b/rpc/rpc_client.go index 862b6fb1c1c..afc8a3c6c63 100644 --- a/rpc/rpc_client.go +++ b/rpc/rpc_client.go @@ -49,6 +49,7 @@ var ( // UseSyncLoginRPC for tests where we dont need to execute as a goroutine UseSyncLoginRPC bool + connectionDialingWG sync.WaitGroup AnalyticsSerializers []serializer.AnalyticsSerializer ) @@ -257,8 +258,12 @@ func Connect(connConfig Config, suppressRegister bool, dispatcherFuncs map[strin clientSingleton.Conns = 5 } - clientSingleton.Dial = func(addr string) (conn net.Conn, err error) { + for i := 0; i < clientSingleton.Conns; i++ { + connectionDialingWG.Add(1) + } + clientSingleton.Dial = func(addr string) (conn net.Conn, err error) { + defer connectionDialingWG.Done() dialer := &net.Dialer{ Timeout: 10 * time.Second, KeepAlive: 30 * time.Second, @@ -294,8 +299,10 @@ func Connect(connConfig Config, suppressRegister bool, dispatcherFuncs map[strin conn.Write([]byte("proto2")) conn.Write([]byte{byte(len(connID))}) conn.Write([]byte(connID)) + return conn, nil } + clientSingleton.Start() loadDispatcher(dispatcherFuncs) @@ -304,11 +311,14 @@ func Connect(connConfig Config, suppressRegister bool, dispatcherFuncs map[strin funcClientSingleton = dispatcher.NewFuncClient(clientSingleton) } + // wait until all the pool connections are dialed so we can call login + connectionDialingWG.Wait() handleLogin() if !suppressRegister { register() go checkDisconnect() } + return true }