From c01d4ecb504c79583ebf0eab577db065a7a02b9c Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Mon, 21 Nov 2022 19:13:00 +0300 Subject: [PATCH] [#2080] morph: Close morph clients Could be related to "websocket users limit reached" on the `neo-go` server side when an SN/IR is rebooting repeatedly. Signed-off-by: Pavel Karpy --- CHANGELOG.md | 1 + cmd/neofs-node/morph.go | 2 ++ pkg/morph/client/constructor.go | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6ef4566a..ad5a01437 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ Changelog for NeoFS Node - ObjectID signature output in the CLI (#2104) - Pack arguments of `setPrice` invocation during contract update (#2078) - `neofs-cli object hash` panic (#2079) +- Closing `neo-go` WS clients on shutdown and switch processes (#2080) ### Removed - `-g` option from `neofs-cli control ...` and `neofs-cli container create` commands (#2089) diff --git a/cmd/neofs-node/morph.go b/cmd/neofs-node/morph.go index 4ceee9e3f..21db514f3 100644 --- a/cmd/neofs-node/morph.go +++ b/cmd/neofs-node/morph.go @@ -62,6 +62,8 @@ func initMorphComponents(c *cfg) { fatalOnErr(err) } + c.onShutdown(cli.Close) + if err := cli.SetGroupSignerScope(); err != nil { c.log.Info("failed to set group signer scope, continue with Global", zap.Error(err)) } diff --git a/pkg/morph/client/constructor.go b/pkg/morph/client/constructor.go index 958af3320..7096511bc 100644 --- a/pkg/morph/client/constructor.go +++ b/pkg/morph/client/constructor.go @@ -153,6 +153,12 @@ func (c *Client) newCli(endpoint string) (*rpcclient.WSClient, *actor.Actor, err return nil, nil, fmt.Errorf("WS client creation: %w", err) } + defer func() { + if err != nil { + cli.Close() + } + }() + err = cli.Init() if err != nil { return nil, nil, fmt.Errorf("WS client initialization: %w", err)