forked from TrueCloudLab/frostfs-node
[#72] Shutdown inner ring app if RPC node has been terminated
Adopt error channel from Listener interface. Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
ccbb9ce6ab
commit
dd48666357
2 changed files with 27 additions and 6 deletions
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/nspcc-dev/neofs-node/pkg/util/grace"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/util/profiler"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -44,6 +45,7 @@ func main() {
|
|||
exitErr(err)
|
||||
|
||||
ctx := grace.NewGracefulContext(log)
|
||||
intErr := make(chan error) // internal inner ring errors
|
||||
|
||||
pprof := profiler.NewProfiler(log, cfg)
|
||||
prometheus := profiler.NewMetrics(log, cfg)
|
||||
|
@ -66,15 +68,19 @@ func main() {
|
|||
}
|
||||
|
||||
// start inner ring
|
||||
err = innerRing.Start(ctx)
|
||||
err = innerRing.Start(ctx, intErr)
|
||||
if err != nil {
|
||||
exitErr(err)
|
||||
}
|
||||
|
||||
log.Info("application started")
|
||||
|
||||
// todo: select ctx.Done or exported error channel
|
||||
<-ctx.Done()
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
case err := <-intErr:
|
||||
// todo: restart application instead of shutdown
|
||||
log.Info("internal error", zap.String("msg", err.Error()))
|
||||
}
|
||||
|
||||
innerRing.Stop()
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ const (
|
|||
)
|
||||
|
||||
// Start runs all event providers.
|
||||
func (s *Server) Start(ctx context.Context) error {
|
||||
func (s *Server) Start(ctx context.Context, intError chan<- error) error {
|
||||
err := s.initConfigFromBlockchain()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -83,8 +83,23 @@ func (s *Server) Start(ctx context.Context) error {
|
|||
|
||||
s.localTimers.Start(ctx) // local timers start ticking
|
||||
|
||||
go s.morphListener.Listen(ctx) // listen for neo:morph events
|
||||
go s.mainnetListener.Listen(ctx) // listen for neo:mainnet events
|
||||
morphErr := make(chan error)
|
||||
mainnnetErr := make(chan error)
|
||||
|
||||
// anonymous function to multiplex error channels
|
||||
go func() {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case err := <-morphErr:
|
||||
intError <- errors.Wrap(err, "sidechain")
|
||||
case err := <-mainnnetErr:
|
||||
intError <- errors.Wrap(err, "mainnet")
|
||||
}
|
||||
}()
|
||||
|
||||
go s.morphListener.ListenWithError(ctx, morphErr) // listen for neo:morph events
|
||||
go s.mainnetListener.ListenWithError(ctx, mainnnetErr) // listen for neo:mainnet events
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue