mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 04:47:18 +00:00
Revert "QSP-42 Remove Double Unsubscribe in Initial Sync" (#6376)
* Revert "QSP-42 Remove Double Unsubscribe in Initial Sync (#6368)"
This reverts commit 637354f037
.
* comment
* add go fmt
This commit is contained in:
parent
e9a597b43c
commit
e45a06cbf1
@ -80,7 +80,17 @@ func (s *Service) Start() {
|
||||
// Wait for state to be initialized.
|
||||
stateChannel := make(chan *feed.Event, 1)
|
||||
stateSub := s.stateNotifier.StateFeed().Subscribe(stateChannel)
|
||||
for genesisSet := false; !genesisSet; {
|
||||
// We have two instances in which we call unsubscribe. The first
|
||||
// instance below is to account for the fact that we exit
|
||||
// the for-select loop through a return when we receive a closed
|
||||
// context or error from our subscription. The only way to correctly
|
||||
// close the subscription would be through a defer. The second instance we
|
||||
// call unsubscribe when we have already received the state
|
||||
// initialized event and are proceeding with the main synchronization
|
||||
// routine.
|
||||
defer stateSub.Unsubscribe()
|
||||
genesisSet := false
|
||||
for !genesisSet {
|
||||
select {
|
||||
case event := <-stateChannel:
|
||||
if event.Type == statefeed.Initialized {
|
||||
@ -95,10 +105,10 @@ func (s *Service) Start() {
|
||||
}
|
||||
case <-s.ctx.Done():
|
||||
log.Debug("Context closed, exiting goroutine")
|
||||
break
|
||||
return
|
||||
case err := <-stateSub.Err():
|
||||
log.WithError(err).Error("Subscription to state notifier failed")
|
||||
break
|
||||
return
|
||||
}
|
||||
}
|
||||
stateSub.Unsubscribe()
|
||||
|
Loading…
Reference in New Issue
Block a user