From 6508136204a0ddd698963b1bf2c161f54b8cc8a2 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Thu, 31 Mar 2022 15:46:28 +0300 Subject: [PATCH] [#1170] ir, node: Stop the app on WS connection lost Signed-off-by: Pavel Karpy --- cmd/neofs-ir/main.go | 2 +- cmd/neofs-node/morph.go | 3 +++ pkg/innerring/innerring.go | 11 +++++++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cmd/neofs-ir/main.go b/cmd/neofs-ir/main.go index c473d727f..3c2105b75 100644 --- a/cmd/neofs-ir/main.go +++ b/cmd/neofs-ir/main.go @@ -69,7 +69,7 @@ func main() { httpServers := initHTTPServers(cfg) - innerRing, err := innerring.New(ctx, log, cfg) + innerRing, err := innerring.New(ctx, log, cfg, intErr) exitErr(err) // start HTTP servers diff --git a/cmd/neofs-node/morph.go b/cmd/neofs-node/morph.go index a33401e9c..ded9832be 100644 --- a/cmd/neofs-node/morph.go +++ b/cmd/neofs-node/morph.go @@ -47,6 +47,9 @@ func initMorphComponents(c *cfg) { client.WithDialTimeout(morphconfig.DialTimeout(c.appCfg)), client.WithLogger(c.log), client.WithExtraEndpoints(addresses[1:]), + client.WithConnLostCallback(func() { + c.internalErr <- errors.New("morph connection has been lost") + }), ) if err != nil { c.log.Info("failed to create neo RPC client", diff --git a/pkg/innerring/innerring.go b/pkg/innerring/innerring.go index 9d11b6565..d10b4f52b 100644 --- a/pkg/innerring/innerring.go +++ b/pkg/innerring/innerring.go @@ -313,7 +313,7 @@ func (s *Server) registerStarter(f func() error) { } // New creates instance of inner ring sever structure. -func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error) { +func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper, errChan chan<- error) (*Server, error) { var err error server := &Server{log: log} @@ -354,7 +354,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error } // create morph client - server.morphClient, err = createClient(ctx, morphChain) + server.morphClient, err = createClient(ctx, morphChain, errChan) if err != nil { return nil, err } @@ -389,7 +389,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error mainnetChain.from = fromMainChainBlock // create mainnet client - server.mainnetClient, err = createClient(ctx, mainnetChain) + server.mainnetClient, err = createClient(ctx, mainnetChain, errChan) if err != nil { return nil, err } @@ -946,7 +946,7 @@ func createListener(ctx context.Context, cli *client.Client, p *chainParams) (ev return listener, err } -func createClient(ctx context.Context, p *chainParams) (*client.Client, error) { +func createClient(ctx context.Context, p *chainParams, errChan chan<- error) (*client.Client, error) { // config name left unchanged for compatibility, may be its better to rename it to "endpoints" or "clients" endpoints := p.cfg.GetStringSlice(p.name + ".endpoint.client") if len(endpoints) == 0 { @@ -961,6 +961,9 @@ func createClient(ctx context.Context, p *chainParams) (*client.Client, error) { client.WithDialTimeout(p.cfg.GetDuration(p.name+".dial_timeout")), client.WithSigner(p.sgn), client.WithExtraEndpoints(endpoints[1:]), + client.WithConnLostCallback(func() { + errChan <- fmt.Errorf("%s chain connection has been lost", p.name) + }), ) }