Count remote echo timeouts from ack instead of event ts

This commit is contained in:
Tulir Asokan 2024-06-08 12:47:41 +03:00
parent 5333dcbbe9
commit 0c7e11d8f0

View file

@ -254,7 +254,7 @@ type PortalMatrixMessage struct {
type outgoingMessage struct {
*event.Event
Acked bool
AckedAt time.Time
Errored bool
Timeouted bool
}
@ -390,7 +390,7 @@ func (portal *Portal) outgoingMessageTimeoutLoop() {
for range ticker.C {
portal.outgoingMessagesLock.Lock()
for _, out := range portal.outgoingMessages {
if !out.Timeouted && out.Acked && !out.Errored && time.Since(time.UnixMilli(out.Timestamp)) > 1*time.Minute {
if !out.Timeouted && !out.AckedAt.IsZero() && !out.Errored && time.Since(out.AckedAt) > 1*time.Minute {
go portal.sendStatusEvent(context.TODO(), out.ID, "", errEchoTimeout, nil)
go portal.sendErrorMessage(context.TODO(), out.Event, errEchoTimeout, "message", false, "")
go portal.bridge.SendMessageCheckpoint(out.Event, status.MsgStepRemote, errEchoTimeout, status.MsgStatusTimeout, 0)
@ -2110,10 +2110,10 @@ func (portal *Portal) HandleMatrixMessage(sender *User, evt *event.Event, timing
go ms.sendMessageMetrics(ctx, sender, evt, err, "Error sending", true)
} else if resp.Status != gmproto.SendMessageResponse_SUCCESS {
outgoingMsg.Errored = true
outgoingMsg.Acked = true
outgoingMsg.AckedAt = time.Now()
go ms.sendMessageMetrics(ctx, sender, evt, (*responseStatusError)(resp), "Error sending", true)
} else {
outgoingMsg.Acked = true
outgoingMsg.AckedAt = time.Now()
go ms.sendMessageMetrics(ctx, sender, evt, nil, "", true)
}
}