We have been experiencing timeout issues with some of our requests very rarely and occasionally. It is difficult to reproduce as it just happens out of nowhere and on retry (resending the request by doing the exact same action, like pressing a button) we would most likely successfully get a response back. This has happened on different devices.
Here our platform info: XCode 10.1 Swift 4.2 Alamofire 4.8.1 PromiseKit 6.8.3
Here is one of our request examples:
public class NetworkingHelpers {
// MARK: Singleton
public static let shared = NetworkingHelpers()
private let alamofireManager: SessionManager
// MARK: Init
private init() {
let configuration = URLSessionConfiguration.default
configuration.timeoutIntervalForRequest = 30
configuration.timeoutIntervalForResource = 30
alamofireManager = Alamofire.SessionManager(configuration: configuration)
}
public func makePublicRequest<T: Decodable>(url: String, decodeAsType: T.Type, method: HTTPMethod = .get,
params: [String: Any]? = nil) -> Promise<T> {
return alamofireManager.request(url, method: method, parameters: params, encoding: JSONEncoding.default, headers: self.anonymousHeaders)
.response(.promise)
.recover(policy: .allErrorsExceptCancellation) { error -> Promise<(URLRequest, HTTPURLResponse, Data)> in
// This is a error thrown by the alamofireManager, but not from the server
// Most likely it is a timeout
let e = error as NSError
throw RequestErrorUtils.generateRequestError(e.code)
}
.then { (request, response, data) -> Promise<T> in
// Process response
}
}
If timeout, Alamofire
throws error -1001
code to us which is the 30 seconds timeout error. That also means the alamofireManager
has processed the request we made.
This happens very randomly and as we mentioned, it will mostly be successful with a manual retry. We failed to capture any logs from our server side. We have a few hypothesis to this issue.
- iOS is buggy where it loses requests randomly and occasionally
- Alamofire is buggy where it loses requests randomly and occasionally
- Our network drops randomly and occasionally
- Our server fails to respond randomly and occasionally
We will also use Netfox
to snoop the requests from our devices so that we can narrow the problem down.
Does anyone have similar problems before? Thanks!