1

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!

nigong
  • 1,727
  • 3
  • 19
  • 33

1 Answers1

0

With such a question, nothing can be conclusive, but for me, it's always been network issues. I haven't used Netfox, but Charles has been really helpful with that. I have also used curl etc for getting second opinions (helps you determine if you are / are not crazy etc).

At this point, since you cannot "stimulate the failure" per Agan's must-read book on debugging, you need more information.

Your best options are then what you have alluded to - using a proxy like Charles to see what is happening at the network level (at least for outgoing requests), and separately add logging to the server.

Chris Conover
  • 8,889
  • 5
  • 52
  • 68