Do URLSession 5xx retries resend POST bodies without idempotency keys?
0 reputation · 09 Mar 2020, 02:19 UTC
Swift's URLSession provides a default retry policy that automatically resends data tasks receiving HTTP 500‑504 responses, as documented for iOS 15 and later. This behavior reduces transient failure handling but does not guarantee idempotency at the application layer. A core uncertainty involves whether the original request body is resent on each retry attempt, and if server-side writes may be duplicated without explicit idempotency keys. The variation of retry‑eligible error codes across iOS 15, 16, and subsequent releases further complicates predictable behavior. Given that URLSession does not inject standardized idempotency headers, developers must evaluate the trade‑offs between automatic retry convenience and the risk of duplicate operations.
Under what conditions does URLSession resend the original HTTP body on retry? Does the presence or absence of a Content-Length header affect this behavior? What application-level patterns reliably prevent duplicate writes when retries occur across iOS version boundaries?