Only send unknown error state after 2 ping fails

This commit is contained in:
Tulir Asokan 2023-11-06 16:05:21 +02:00
parent a94ccb0489
commit cb5f3fa3f9
3 changed files with 12 additions and 8 deletions

View file

@ -82,5 +82,6 @@ type PhoneNotResponding struct{}
type PhoneRespondingAgain struct{} type PhoneRespondingAgain struct{}
type PingFailed struct { type PingFailed struct {
Error error Error error
ErrorCount int
} }

View file

@ -25,28 +25,29 @@ const phoneNotRespondingTimeout = 30 * time.Second
func (c *Client) doDittoPinger(log *zerolog.Logger, dittoPing <-chan struct{}, stopPinger <-chan struct{}) { func (c *Client) doDittoPinger(log *zerolog.Logger, dittoPing <-chan struct{}, stopPinger <-chan struct{}) {
notResponding := false notResponding := false
pingFailed := false pingFails := 0
exit := false exit := false
onRespond := func() { onRespond := func() {
if notResponding { if notResponding {
log.Debug().Msg("Ditto ping succeeded, phone is back online") log.Debug().Msg("Ditto ping succeeded, phone is back online")
c.triggerEvent(&events.PhoneRespondingAgain{}) c.triggerEvent(&events.PhoneRespondingAgain{})
notResponding = false notResponding = false
pingFailed = false pingFails = 0
} else if pingFailed { } else if pingFails > 0 {
// TODO separate event? // TODO separate event?
c.triggerEvent(&events.PhoneRespondingAgain{}) c.triggerEvent(&events.PhoneRespondingAgain{})
pingFailed = false pingFails = 0
} }
} }
doPing := func() { doPing := func() {
pingChan, err := c.NotifyDittoActivity() pingChan, err := c.NotifyDittoActivity()
if err != nil { if err != nil {
log.Err(err).Msg("Error notifying ditto activity") log.Err(err).Msg("Error notifying ditto activity")
pingFails++
c.triggerEvent(&events.PingFailed{ c.triggerEvent(&events.PingFailed{
Error: fmt.Errorf("failed to notify ditto activity: %w", err), Error: fmt.Errorf("failed to notify ditto activity: %w", err),
ErrorCount: pingFails,
}) })
pingFailed = true
return return
} }
select { select {

View file

@ -598,12 +598,14 @@ func (user *User) syncHandleEvent(event any) {
"go_error": v.Error.Error(), "go_error": v.Error.Error(),
}, },
}, false) }, false)
} else { } else if v.ErrorCount > 1 {
user.BridgeState.Send(status.BridgeState{ user.BridgeState.Send(status.BridgeState{
StateEvent: status.StateUnknownError, StateEvent: status.StateUnknownError,
Error: GMPingFailed, Error: GMPingFailed,
Info: map[string]any{"go_error": v.Error.Error()}, Info: map[string]any{"go_error": v.Error.Error()},
}) })
} else {
user.zlog.Debug().Msg("Not sending unknown error for first ping fail")
} }
case *events.PairSuccessful: case *events.PairSuccessful:
user.Session = user.Client.AuthData user.Session = user.Client.AuthData