Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
Update msg.Term()/msg.Ack()
Browse files Browse the repository at this point in the history
  • Loading branch information
S7evinK committed Dec 18, 2023
1 parent d8f3148 commit 96d1fb8
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions roomserver/internal/input/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ func (w *worker) _next() {
msg := msgs[0]
var inputRoomEvent api.InputRoomEvent
if err = json.Unmarshal(msg.Data, &inputRoomEvent); err != nil {
_ = msg.Term()
// using AckWait here makes the call synchronous; 5 seconds is default value
_ = msg.Term(nats.AckWait(time.Second * 5))
return
}

Expand Down Expand Up @@ -346,10 +347,15 @@ func (w *worker) _next() {
"type": inputRoomEvent.Event.Type(),
}).Warn("Roomserver failed to process event")
}
_ = msg.Term()
// Even though we failed to process this message (e.g. due to Dendrite restarting and receiving a context canceled),
// the message may already have been queued for redelivery or will be, so this makes sure that we still reprocess the msg
// after restarting. We only Ack if the context was not yet canceled.
if w.r.ProcessContext.Context().Err() == nil {
_ = msg.AckSync()
}
errString = err.Error()
} else {
_ = msg.Ack()
_ = msg.AckSync()
}

// If it was a synchronous input request then the "sync" field
Expand Down

0 comments on commit 96d1fb8

Please sign in to comment.