"The request timed out" error when calling Realm function

When I try to login as anonymous or call a Realm function from my iOS app (especially when I haven’t called the function recently), I frequently get the following error:

2021-10-22 09:05:02.573174-0700 RealmUserIdentitesTest[88772:7786117] Task <B5C71D3D-7C87-4BDF-83CD-214B4D72A695>.<1> finished with error [-1001] Error Domain=NSURLErrorDomain Code=-1001 The request timed out. UserInfo={_kCFStreamErrorCodeKey=-2102, NSUnderlyingError=0x6000025904e0 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 (null) UserInfo={_kCFStreamErrorCodeKey=-2102, _kCFStreamErrorDomainKey=4}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <B5C71D3D-7C87-4BDF-83CD-214B4D72A695>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=(

LocalDataTask <B5C71D3D-7C87-4BDF-83CD-214B4D72A695>.<1>
), NSLocalizedDescription=The request timed out., NSErrorFailingURLStringKey=https://realm.mongodb.com/api/client/v2.0/app/development-elias-euurf/location, NSErrorFailingURLKey=https://realm.mongodb.com/api/client/v2.0/app/development-elias-euurf/location, _kCFStreamErrorDomainKey=4}

If I print the error in the console, it just reads “The request timed out”.

I’m using version v10.17.0 of Realm, installed using Carthage.

Do you know what the cause of this error is? How do I prevent it from occurring?

Hi @Elias_Heffan ,

There can be multiple reasons for a timeout: if you are on a free tier, for example, you have some limitations, and your instance may not be immediately available, as the low tiers are shared, and your app may be in a non-active state.

It’s also important to take into considerations the deployment model of your Realm App: anything that hasn’t a Local deployment on specific AWS regions is going to suffer a performance hit, with the current setup.

Last but not least, please note that anonymous logins are meant for temporary use: an anonymous user will, at some point, have its auth token expired, and all data connected to it will be lost.

Hi @Paolo_Manna,

Thanks for the helpful response. I’m thinking that the problem is likely due to the first point you mentioned; maybe using the free tier for our development Realm app and database is causing it to take longer to respond. I decided to set the default timeout to 90 seconds to allow enough time for the response to come back. So far, it appears to be working.

For anyone else who is experiencing this issue, here’s how I configured the longer timeout:

let configuration = AppConfiguration(
  baseURL: nil,
  transport: nil,
  localAppName: nil,
  localAppVersion: nil,
  defaultRequestTimeoutMS: 90 * 1000
let realmApp = RealmSwift.App(id: "<realm-app-id>", configuration: configuration)

Also, I read the implementation code for the timeout, and it appears to be only 6 seconds by default. Is that correct?