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 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{}) {
notResponding := false
pingFailed := false
pingFails := 0
exit := false
onRespond := func() {
if notResponding {
log.Debug().Msg("Ditto ping succeeded, phone is back online")
c.triggerEvent(&events.PhoneRespondingAgain{})
notResponding = false
pingFailed = false
} else if pingFailed {
pingFails = 0
} else if pingFails > 0 {
// TODO separate event?
c.triggerEvent(&events.PhoneRespondingAgain{})
pingFailed = false
pingFails = 0
}
}
doPing := func() {
pingChan, err := c.NotifyDittoActivity()
if err != nil {
log.Err(err).Msg("Error notifying ditto activity")
pingFails++
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
}
select {

View file

@ -598,12 +598,14 @@ func (user *User) syncHandleEvent(event any) {
"go_error": v.Error.Error(),
},
}, false)
} else {
} else if v.ErrorCount > 1 {
user.BridgeState.Send(status.BridgeState{
StateEvent: status.StateUnknownError,
Error: GMPingFailed,
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:
user.Session = user.Client.AuthData