URLSession fails with error -1001, the request timed out
Error 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.
Fix it fast
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)2Match what you see, then jump to its fix
- 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
Only some calls time out, and those calls use their own URLRequestA short timeoutInterval is set on one URLRequestFix - 3
Big uploads or downloads fail even though data keeps arrivingA large transfer outlasts the resource timeoutFix
- 1
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/slow2Fix
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 timeoutIntervalForRequestConfirmed by developer.apple.com
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 = 603Verify
Run the failing call again.
grep -rn "timeoutInterval" --include=*.swift .Confirmed by developer.apple.com
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 = 36003Verify
Transfer the largest file on a slow connection and check that it finishes.
grep -rn "timeoutIntervalForResource" --include=*.swift .Confirmed by developer.apple.com
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
Mobile apps
URLSession fails with error -1005, the network connection was lost
URLError.networkConnectionLost
Error -1005 means the TCP connection carrying your HTTP request dropped while the request was in progress.
3 causes, each with a fixMobile apps
UserDefaults logs 'Failed to read values in CFPrefsPlistSource' for an app group
Settings saved by the app are not visible to its extension, widget or sibling app that share the group
This log comes from the preferences system when UserDefaults is opened for an app group's suite.
3 causes, each with a fixMobile apps
iOS app crashes: Google Maps SDK must be initialized via provideAPIKey
Google Maps SDK for iOS must be initialized via [GMSServices provideAPIKey:...] prior to use
The Maps SDK throws this when a Maps object is created before GMSServices.provideAPIKey has run.
3 causes, each with a fixMobile apps
UIKit app crashes because it cannot find the storyboard
Could not find a storyboard named 'Main' in bundle NSBundle
UIStoryboard throws this exception when no storyboard file with that name exists in the bundle it searches.
3 causes, each with a fixMobile apps
Firebase on iOS asks for the FCM token before APNs has given one
Be sure to re-retrieve the FCM token once the APNS device token is set.
The Firebase Messaging SDK needs the APNs device token from iOS before it hands out an FCM token.
3 causes, each with a fixMobile apps
A test push from the Firebase console never shows up on the iPhone
didReceiveRegistrationToken prints a token, yet no notification arrives
When a console message is accepted but the iPhone stays silent, the break is between Firebase and APNs or inside the app.
4 causes, each with a fix