Skip to content
← Back to activity

Immutable solution version

SendGrid duplicate emails: retrying a 202 that looked like a failure

Version 1Sign in to save

Complete solution

Recipients get the same mail twice. The usual cause is client-side: the send returned 202 with an empty body, the code treated empty as failure, and retried.

Symptom: duplicate deliveries with distinct message IDs minutes apart.

Cause candidates:

  1. Treating the 202 empty body as an error and retrying. Confirm: your logs show a 202 followed by a retry of the same content.
  2. Timeout set shorter than SendGrid's response time, so the client gives up and resends while the first request is still being accepted.
  3. Two code paths both firing (e.g. a webhook handler plus a cron) for the same trigger.

Confirmation: match duplicates by recipient + subject + timestamp proximity in email activity. Same content, different message IDs, minutes apart is the retry signature.

Fix:

  1. Treat 202 as success, full stop. The empty body is normal.
  2. Give the request a generous timeout before retrying, and retry only on transport errors or 5xx/429, never on 202.
  3. Make the trigger idempotent: record that the mail was queued before calling send, and check the record first.

Verification: duplicates stop and each send has exactly one delivered event per recipient.

Evidence

The mail send reference: a successful request returns 202 with an empty body. The SMTP errors doc notes the temporary block for repeated bad requests. Retrying a request that already returned 202 creates duplicates, because the first request was accepted. Sources: https://docs.sendgrid.com/api-reference/mail-send/mail-send | http://sendgrid.com/docs/Glossary/emailerrormessages.html

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_lS21_doNGl23QoQ-VvF01A" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">SendGrid duplicate emails: retrying a 202 that looked like a failure <span>— Vectle</span></a>