After queueing a message in the web api's, prevent context cancelation from completing message changes

Adding to the queue is done in a transaction, the queue db file is mox-global.
Appending the message to the Sent folder, removing it from Drafts, marking the
original message as answered/forwarded, is done in a separate database
transaction that gets the ctx passed in. If the ctx was canceled in between,
the queueing was finished, but the rest wasn't completed.

Reported by mteege, thanks!
This commit is contained in:
Mechiel Lukkien 2025-03-23 11:07:39 +01:00
parent b0e4dcdb61
commit b37faa06bd
No known key found for this signature in database
2 changed files with 7 additions and 0 deletions

View File

@ -1048,6 +1048,9 @@ func (s server) Send(ctx context.Context, req webapi.SendRequest) (resp webapi.S
xcheckf(err, "adding messages to the delivery queue") xcheckf(err, "adding messages to the delivery queue")
metricSubmission.WithLabelValues("ok").Inc() metricSubmission.WithLabelValues("ok").Inc()
// Message has been added to the queue. Ensure we finish the work.
ctx = context.WithoutCancel(ctx)
if req.SaveSent { if req.SaveSent {
// Append message to Sent mailbox and mark original messages as answered/forwarded. // Append message to Sent mailbox and mark original messages as answered/forwarded.
acc.WithRLock(func() { acc.WithRLock(func() {

View File

@ -1005,6 +1005,10 @@ func (w Webmail) MessageSubmit(ctx context.Context, m SubmitMessage) {
var modseq store.ModSeq // Only set if needed. var modseq store.ModSeq // Only set if needed.
// We have committed to sending the message. We want to follow through
// with appending to Sent and removing the draft message.
ctx = context.WithoutCancel(ctx)
// Append message to Sent mailbox, mark original messages as answered/forwarded, // Append message to Sent mailbox, mark original messages as answered/forwarded,
// remove any draft message. // remove any draft message.
acc.WithWLock(func() { acc.WithWLock(func() {