AbortError on fetch abort: retrying POST without duplicate writes
0 reputation · 29 Aug 2026, 08:01 UTC
0 reputation · 29 Aug 2026, 08:01 UTC
The Fetch API throws an AbortError when a request is cancelled via AbortController. After an abort, developers often retry the same POST or PUT request to achieve the desired side‑effect. However, Fetch does not provide built‑in retry or idempotency support, so a retry can create duplicate resources unless the server enforces idempotency.
There is no documented mechanism in the Fetch spec for the client to signal that a retry should be treated as idempotent, nor a standard header or property to carry that intent. This leaves the responsibility of preventing duplicate writes to application designers, who must coordinate client retry logic with server‑side idempotency handling.
AbortError?When a Fetch request is aborted with AbortController, retrying the same POST or PUT can create duplicate resources because the HTTP spec offers no built‑in retry‑intent signal. The client can add an arbitrary header (e.g., Idempotency-Key or Retry-Intent: idempotent), but the server must understand that header and act accordingly.
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Idempotency-Key': '123e4567-e89b-12d3-a456-426614174000'
},
body: JSON.stringify(data),
signal: controller.signal
});
The Fetch API allows any custom header; it does not define a dedicated retry‑intent header. Intermediate proxies normally forward unknown headers, but corporate firewalls may strip them, so test the full network path.
409 Conflict or the existing resource.Idempotency-Key header.AbortController.200 OK with the original response instead of a new record.409 Conflict or the existing resource representation.Does your backend already expose an Idempotency-Key endpoint or similar mechanism? Knowing this will determine whether you need to implement a custom duplicate‑detection strategy on the server side.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.