Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

URLSession fails with error -1001, the request timed out

ErrorError Domain=NSURLErrorDomain Code=-1001 "The request timed out."

Short answer

Error -1001 means a URLSession timer ran out before the load finished. The usual timer is the request timeout: 60 seconds without new data by default. Find out which timeout fired and whether the server was slow or your own value was too short. Then change the server, the timeout, or switch large transfers to a longer limit.

  • Applies to Xcode 26, Swift 6, iOS 26, URLSession
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print every timeout you set, on the request and on the session configuration. A value you forgot about is the most common finding.

    print("request:", request.timeoutInterval)
    print("session request:", session.configuration.timeoutIntervalForRequest)
    print("session resource:", session.configuration.timeoutIntervalForResource)
  2. 2Match what you see, then jump to its fix

    1. 1-1001 after about 60 seconds on a slow endpoint (or after your own shorter value)The server sends nothing for longer than the request timeoutFix
    2. 2Only some calls time out, and those calls use their own URLRequestA short timeoutInterval is set on one URLRequestFix
    3. 3Big uploads or downloads fail even though data keeps arrivingA large transfer outlasts the resource timeoutFix

What does the error look like?

  • Error Domain=NSURLErrorDomain Code=-1001 "The request timed out."
  • URLError.timedOut

Cause 1 of 3

The server sends nothing for longer than the request timeout

1Check

The request timeout is how long a task waits for more data. The timer restarts whenever data arrives. The default is 60 seconds. If an endpoint works for a minute before the first byte, it times out. Time the call outside the app.

curl -o /dev/null -s -w "first byte: %{time_starttransfer}s total: %{time_total}s\n" https://api.example.com/slow

2Fix

Make the endpoint answer sooner, or have it accept the job and return at once, with a second call for the result. Raise the timeout only for requests that really need it.

let config = URLSessionConfiguration.default
config.timeoutIntervalForRequest = 120
let session = URLSession(configuration: config)

3Verify

Repeat the slow call and confirm it finishes or fails with a different error.

# call the endpoint again and compare the printed time with timeoutIntervalForRequest

Confirmed by developer.apple.com

Did this fix it?

Cause 2 of 3

A short timeoutInterval is set on one URLRequest

1Check

Apple documents that a session reports URLError.timedOut when the request's timeoutInterval expires before the load can complete. A value set on a single request wins over your intent for the whole app. Search for places that set it.

grep -rn "timeoutInterval" --include=*.swift .

2Fix

Remove the override, or give that request a value that fits the endpoint.

var request = URLRequest(url: url)
request.timeoutInterval = 60

3Verify

Run the failing call again.

grep -rn "timeoutInterval" --include=*.swift .

Confirmed by developer.apple.com

Did this fix it?

Cause 3 of 3

A large transfer outlasts the resource timeout

1Check

The resource timeout counts from when the request starts until the whole resource has transferred. The default is 7 days, so it fires only when someone lowered it. Check whether your configuration sets it.

grep -rn "timeoutIntervalForResource" --include=*.swift .

2Fix

Raise the value to fit the largest file on the slowest network you support, or remove the override.

let config = URLSessionConfiguration.default
config.timeoutIntervalForResource = 3600

3Verify

Transfer the largest file on a slow connection and check that it finishes.

grep -rn "timeoutIntervalForResource" --include=*.swift .

Confirmed by developer.apple.com

Did this fix it?

How do I stop it coming back?

  • Keep all timeout values in one place, so no call carries a hidden override.
  • Do long server work in a background job and return a job ID within seconds.
  • Log the URL, the method and the elapsed time with every -1001.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.