[#1170] ir, node: Stop the app on WS connection lost
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
2427593da6
commit
6508136204
3 changed files with 11 additions and 5 deletions
|
@ -69,7 +69,7 @@ func main() {
|
||||||
|
|
||||||
httpServers := initHTTPServers(cfg)
|
httpServers := initHTTPServers(cfg)
|
||||||
|
|
||||||
innerRing, err := innerring.New(ctx, log, cfg)
|
innerRing, err := innerring.New(ctx, log, cfg, intErr)
|
||||||
exitErr(err)
|
exitErr(err)
|
||||||
|
|
||||||
// start HTTP servers
|
// start HTTP servers
|
||||||
|
|
|
@ -47,6 +47,9 @@ func initMorphComponents(c *cfg) {
|
||||||
client.WithDialTimeout(morphconfig.DialTimeout(c.appCfg)),
|
client.WithDialTimeout(morphconfig.DialTimeout(c.appCfg)),
|
||||||
client.WithLogger(c.log),
|
client.WithLogger(c.log),
|
||||||
client.WithExtraEndpoints(addresses[1:]),
|
client.WithExtraEndpoints(addresses[1:]),
|
||||||
|
client.WithConnLostCallback(func() {
|
||||||
|
c.internalErr <- errors.New("morph connection has been lost")
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.log.Info("failed to create neo RPC client",
|
c.log.Info("failed to create neo RPC client",
|
||||||
|
|
|
@ -313,7 +313,7 @@ func (s *Server) registerStarter(f func() error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates instance of inner ring sever structure.
|
// 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
|
var err error
|
||||||
server := &Server{log: log}
|
server := &Server{log: log}
|
||||||
|
|
||||||
|
@ -354,7 +354,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
}
|
}
|
||||||
|
|
||||||
// create morph client
|
// create morph client
|
||||||
server.morphClient, err = createClient(ctx, morphChain)
|
server.morphClient, err = createClient(ctx, morphChain, errChan)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -389,7 +389,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
mainnetChain.from = fromMainChainBlock
|
mainnetChain.from = fromMainChainBlock
|
||||||
|
|
||||||
// create mainnet client
|
// create mainnet client
|
||||||
server.mainnetClient, err = createClient(ctx, mainnetChain)
|
server.mainnetClient, err = createClient(ctx, mainnetChain, errChan)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -946,7 +946,7 @@ func createListener(ctx context.Context, cli *client.Client, p *chainParams) (ev
|
||||||
return listener, err
|
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"
|
// 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")
|
endpoints := p.cfg.GetStringSlice(p.name + ".endpoint.client")
|
||||||
if len(endpoints) == 0 {
|
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.WithDialTimeout(p.cfg.GetDuration(p.name+".dial_timeout")),
|
||||||
client.WithSigner(p.sgn),
|
client.WithSigner(p.sgn),
|
||||||
client.WithExtraEndpoints(endpoints[1:]),
|
client.WithExtraEndpoints(endpoints[1:]),
|
||||||
|
client.WithConnLostCallback(func() {
|
||||||
|
errChan <- fmt.Errorf("%s chain connection has been lost", p.name)
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue