Skip to content

fix(network): retry connection-lost requests only for idempotent methods - #446

Merged
MaatheusGois merged 1 commit into
DebugSwift:mainfrom
dimashbk:fix/retry-idempotent-methods
Sep 2, 2026
Merged

MaatheusGois merged 1 commit into
DebugSwift:mainfrom
dimashbk:fix/retry-idempotent-methods

Conversation

@dimashbk

@dimashbk dimashbk commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Summary

CustomHTTPProtocol silently re-issues the original request on cfurlErrorNetworkConnectionLost when no data was received — for any HTTP method. Re-issuing non-idempotent requests (POST/PUT/PATCH/DELETE) can duplicate server-side effects: a payment/order POST whose connection drops after reaching the server gets sent twice, and the app never sees the first attempt. Apple's URL loading system deliberately never auto-retries POST on connection-lost for this reason.

This limits the silent retry to idempotent methods (GET/HEAD/OPTIONS/TRACE).

Type of change

  • Fix
  • Feature
  • Refactor
  • Docs
  • CI/CD

Test plan

  • Unit tests updated
  • Manual testing completed
  • CI passing

Manual test steps

  1. Intercept a POST with DebugSwift enabled and kill the connection mid-flight (Network Link Conditioner / proxy) so the task fails with networkConnectionLost before any data arrives.
  2. Before: the request is transparently re-sent (server receives it twice). After: the failure is delivered to the caller, no re-issue.
  3. Repeat with GET — retry still happens as before.

Checklist

  • I reviewed my own changes
  • I updated docs when needed
  • I considered backward compatibility

CustomHTTPProtocol silently re-issued any request (including POST) on
cfurlErrorNetworkConnectionLost; duplicating non-idempotent requests can
repeat server-side effects. Retry now only GET/HEAD/OPTIONS/TRACE.
@MaatheusGois
MaatheusGois merged commit 70885d3 into DebugSwift:main Sep 2, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants