Skip to content

Commit

Permalink
add startonce protection to syncer (#13917)
Browse files Browse the repository at this point in the history
  • Loading branch information
ettec authored Jul 24, 2024
1 parent 780d304 commit c5224df
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/friendly-needles-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

#internal syncer start onc3
23 changes: 14 additions & 9 deletions core/services/registrysyncer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Syncer interface {
}

type registrySyncer struct {
services.StateMachine
stopCh services.StopChan
launchers []Launcher
reader types.ContractReader
Expand Down Expand Up @@ -118,12 +119,14 @@ func newReader(ctx context.Context, lggr logger.Logger, relayer contractReaderFa
}

func (s *registrySyncer) Start(ctx context.Context) error {
s.wg.Add(1)
go func() {
defer s.wg.Done()
s.syncLoop()
}()
return nil
return s.StartOnce("testAsyncMessageBroker", func() error {
s.wg.Add(1)
go func() {
defer s.wg.Done()
s.syncLoop()
}()
return nil
})
}

func (s *registrySyncer) syncLoop() {
Expand Down Expand Up @@ -232,9 +235,11 @@ func (s *registrySyncer) AddLauncher(launchers ...Launcher) {
}

func (s *registrySyncer) Close() error {
close(s.stopCh)
s.wg.Wait()
return nil
return s.StopOnce("testAsyncMessageBroker", func() error {
close(s.stopCh)
s.wg.Wait()
return nil
})
}

func (s *registrySyncer) Ready() error {
Expand Down

0 comments on commit c5224df

Please sign in to comment.