Skip to content

Commit

Permalink
debug:! decorate store node call with logs
Browse files Browse the repository at this point in the history
  • Loading branch information
siddarthkay committed Apr 11, 2024
1 parent 88c8b2e commit ec02f33
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion protocol/messenger_mailserver_cycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,8 @@ func (m *Messenger) waitForAvailableStoreNode(timeout time.Duration) bool {
// NOTE: https://stackoverflow.com/questions/32705582/how-to-get-time-tick-to-tick-immediately
timeout += time.Second

m.logger.Info(fmt.Sprintf("Waiting for available store node with timeout: %v", timeout))

finish := make(chan struct{})
cancel := make(chan struct{})

Expand All @@ -774,28 +776,38 @@ func (m *Messenger) waitForAvailableStoreNode(timeout time.Duration) bool {
wg.Done()
}()
for !m.isMailserverAvailable(m.getActiveMailserverID()) {
m.logger.Info("Mailserver is not available, waiting...")
select {
case <-m.SubscribeMailserverAvailable():
m.logger.Info("Received mailserver available event")
case <-cancel:
return
m.logger.Info("Waiting for mailserver canceled")
}
}
m.logger.Info("Mailserver is available")
}()

go func() {
defer func() {
close(finish)
}()
wg.Wait()
m.logger.Info("Waiting for mailserver finished")
}()

select {
case <-finish:
m.logger.Info("Mailserver is available, returning true")
case <-time.After(timeout):
close(cancel)
m.logger.Info("Timeout reached, canceling wait")
case <-m.ctx.Done():
m.logger.Info("Context canceled, canceling wait")
close(cancel)
}

return m.isMailserverAvailable(m.getActiveMailserverID())
available := m.isMailserverAvailable(m.getActiveMailserverID())
m.logger.Info(fmt.Sprintf("Mailserver availability: %v", available))
return available
}

0 comments on commit ec02f33

Please sign in to comment.