Repository navigation
fix(email): retry transient SES send failures instead of dropping them - #518
Conversation
…FAILED Co-authored-by: polylane[bot] <277585245+polylane[bot]@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedBot user detected. To trigger a single review, invoke the
|
Deploying usesend with
|
| Latest commit: |
0416fd6
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://47422365.usesend.pages.dev |
| Branch Preview URL: | https://polylane-autofix-f90a192mhud.usesend.pages.dev |
… jitter; server errors and dropped connections stay FAILED to avoid duplicate sends
|
Narrowed after review: the queue now retries only when SES explicitly refuses for the send rate (TooManyRequestsException / Throttling / HTTP 429), since those were definitely not accepted. 5xx, timeouts and dropped connections are recorded as FAILED, as before: SES has no idempotency key, so retrying an ambiguous outcome could send the customer's email twice. Backoff now has 50% jitter so a throttled burst doesn't retry in lockstep. Merged main in. |
|
@KMKoushik I can help with this once you have access to the koushik's Workspace workspace. Link your GitHub account to Polylane to verify your workspace access, and I'll pick this up as soon as it is linked. |
…se that escapes (e.g. SES accepted but saving failed) is unrecoverable, never resent
When Amazon SES refused an outgoing mail for a temporary reason — a throttle, a server error, or a dropped connection — the email worker caught the error, recorded the mail as failed, and returned as if the send had finished. The queue never tried again, so the message was lost for good. With this change the worker throws those temporary errors back to the queue, which retries the email a bounded number of times with a growing delay, and only records a permanent failure for errors that will not clear on their own. The catch block in
executeEmailrecorded every send error as terminal and returned, and the email jobs had noattempts, so a transient failure ended the mail permanently. The analogous webhook delivery path already retries transient failures with attempts and backoff. The rethrow only covers errors SES marks transient, so a rejected message keeps its immediate FAILED record.This change is a declared stopgap: it contains the symptom while the producer's fix is tracked as a follow-up on the issue timeline.
Production impact at
bf4fa63: Email retry change is bounded and additive to error handlingRepository lint:
pnpm run lint(declared in package.json) fails over the whole repository (the declared target takes no file arguments), so the failure is not attributed to this change and did not block it; run it before merging.Fix walkthrough
Watch the fix explained (1:27). Recorded for commit
bf4fa6394a90392f5464701cd65d849c89c5967f.Full analysis
flowchart TD A["queueEmail / queueBulk add the job with EMAIL_JOB_OPTIONS"] --> B["worker runs executeEmail"] B --> C["sendRawEmail throws"] C --> D{"isRetryableSendError and attempts remain?"} D -->|"yes"| E["throw: BullMQ retries after backoff"] E --> B D -->|"no"| F["catch records EmailEvent FAILED and returns"] G["observed before the fix: every throw was recorded FAILED once, with no retry"] -.-> F H["producer left unchanged: SES refuses the send under its quota; no send-rate pacing in the worker"] -.-> CDetection evidence
Affected: Railway account
4e7500cc-fd24-403f-8734-843433c85ceaProduction impact
The change touches only the outbound email worker in the production
unsendapp. The retry applies to errors SES marks transient, adds at most two extra sends per email with exponential backoff, and leaves the terminal-failure path unchanged. I could not read the service's live metrics: the Railway connection returns 403 and the digest is frozen at 2026-10-21, so the load check is empty rather than clear.Affected resources
unsendChecked and not affected (1)
RedisObservability
"Failed to send email"error log inapps/web/src/server/aws/ses.ts#sendRawEmail(existing) shows a send that SES rejected.warnlog[EmailQueueService]: Transient send failure, the queue will retry the emailwithemailId,attempt,attemptsshows a retry handed back to the queue.EmailEventrows withstatus: "FAILED"(existing) remain the record of a terminal failure.Polylane assessed this pull request at
bf4fa63.Causal chain
2 files changed (+307/-2)
apps/web/src/server/service/email-queue-service.ts: modified, +50/-2apps/web/src/server/service/email-queue-service.unit.test.ts: added, +257/-0Lint output
Generated by Polylane. You can ask follow-ups by mentioning @polylane in a comment. If you close this pull request without merging, add a comment that says why. Polylane reads it to make its next fixes better.
Summary by cubic
Retries throttled SES send failures in the email worker instead of marking them permanently FAILED, so a send-rate throttle no longer loses the message. The catch block in
executeEmailrecorded every send error as terminal and returned, and the email jobs had noattempts, so a transient failure ended the mail permanently.UnrecoverableError, so the job fails without resending the email.Written for commit 0416fd6. Summary will update on new commits.