forked from TrueCloudLab/frostfs-node
[#1291] listener: Stop only once
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
77f4a5844b
commit
e62e02815b
2 changed files with 9 additions and 8 deletions
|
@ -282,9 +282,7 @@ func (s *Server) Stop() {
|
||||||
s.setHealthStatus(control.HealthStatus_SHUTTING_DOWN)
|
s.setHealthStatus(control.HealthStatus_SHUTTING_DOWN)
|
||||||
|
|
||||||
go s.morphListener.Stop()
|
go s.morphListener.Stop()
|
||||||
if !s.withoutMainNet {
|
|
||||||
go s.mainnetListener.Stop()
|
go s.mainnetListener.Stop()
|
||||||
}
|
|
||||||
|
|
||||||
for _, c := range s.closers {
|
for _, c := range s.closers {
|
||||||
if err := c(); err != nil {
|
if err := c(); err != nil {
|
||||||
|
|
|
@ -90,7 +90,7 @@ type ListenerParams struct {
|
||||||
type listener struct {
|
type listener struct {
|
||||||
mtx *sync.RWMutex
|
mtx *sync.RWMutex
|
||||||
|
|
||||||
once *sync.Once
|
startOnce, stopOnce *sync.Once
|
||||||
|
|
||||||
started bool
|
started bool
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ var (
|
||||||
//
|
//
|
||||||
// Returns an error if listener was already started.
|
// Returns an error if listener was already started.
|
||||||
func (l listener) Listen(ctx context.Context) {
|
func (l listener) Listen(ctx context.Context) {
|
||||||
l.once.Do(func() {
|
l.startOnce.Do(func() {
|
||||||
if err := l.listen(ctx, nil); err != nil {
|
if err := l.listen(ctx, nil); err != nil {
|
||||||
l.log.Error("could not start listen to events",
|
l.log.Error("could not start listen to events",
|
||||||
zap.String("error", err.Error()),
|
zap.String("error", err.Error()),
|
||||||
|
@ -140,7 +140,7 @@ func (l listener) Listen(ctx context.Context) {
|
||||||
//
|
//
|
||||||
// Returns an error if listener was already started.
|
// Returns an error if listener was already started.
|
||||||
func (l listener) ListenWithError(ctx context.Context, intError chan<- error) {
|
func (l listener) ListenWithError(ctx context.Context, intError chan<- error) {
|
||||||
l.once.Do(func() {
|
l.startOnce.Do(func() {
|
||||||
if err := l.listen(ctx, intError); err != nil {
|
if err := l.listen(ctx, intError); err != nil {
|
||||||
l.log.Error("could not start listen to events",
|
l.log.Error("could not start listen to events",
|
||||||
zap.String("error", err.Error()),
|
zap.String("error", err.Error()),
|
||||||
|
@ -570,7 +570,9 @@ func (l listener) RegisterNotaryHandler(hi NotaryHandlerInfo) {
|
||||||
|
|
||||||
// Stop closes subscription channel with remote neo node.
|
// Stop closes subscription channel with remote neo node.
|
||||||
func (l listener) Stop() {
|
func (l listener) Stop() {
|
||||||
|
l.stopOnce.Do(func() {
|
||||||
l.subscriber.Close()
|
l.subscriber.Close()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *listener) RegisterBlockHandler(handler BlockHandler) {
|
func (l *listener) RegisterBlockHandler(handler BlockHandler) {
|
||||||
|
@ -593,7 +595,8 @@ func NewListener(p ListenerParams) (Listener, error) {
|
||||||
|
|
||||||
return &listener{
|
return &listener{
|
||||||
mtx: new(sync.RWMutex),
|
mtx: new(sync.RWMutex),
|
||||||
once: new(sync.Once),
|
startOnce: new(sync.Once),
|
||||||
|
stopOnce: new(sync.Once),
|
||||||
notificationParsers: make(map[scriptHashWithType]NotificationParser),
|
notificationParsers: make(map[scriptHashWithType]NotificationParser),
|
||||||
notificationHandlers: make(map[scriptHashWithType][]Handler),
|
notificationHandlers: make(map[scriptHashWithType][]Handler),
|
||||||
log: p.Logger,
|
log: p.Logger,
|
||||||
|
|
Loading…
Reference in a new issue