From 2467be0117af59a94d1338a25939ee364a4149ee Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 2 Aug 2022 13:14:13 +0300 Subject: [PATCH] [#1648] morph: Init endpoints before first client creation Sort the endpoint by their priority before the first WS client creation to start the morph client with the highest priority endpoint. Signed-off-by: Pavel Karpy --- pkg/morph/client/constructor.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/morph/client/constructor.go b/pkg/morph/client/constructor.go index 62ebbf558..8ef6f9945 100644 --- a/pkg/morph/client/constructor.go +++ b/pkg/morph/client/constructor.go @@ -107,6 +107,8 @@ func New(key *keys.PrivateKey, opts ...Option) (*Client, error) { closeChan: make(chan struct{}), } + cli.endpoints.init(cfg.endpoints) + if cfg.singleCli != nil { // return client in single RPC node mode that uses // predefined WS client @@ -117,7 +119,7 @@ func New(key *keys.PrivateKey, opts ...Option) (*Client, error) { // inactive mode will be enabled cli.client = cfg.singleCli } else { - ws, err := newWSClient(*cfg, cfg.endpoints[0].Address) + ws, err := newWSClient(*cfg, cli.endpoints.list[0].Address) if err != nil { return nil, fmt.Errorf("could not create morph client: %w", err) } @@ -129,7 +131,6 @@ func New(key *keys.PrivateKey, opts ...Option) (*Client, error) { cli.client = ws } - cli.endpoints.init(cfg.endpoints) go cli.notificationLoop()