URLSession timed out prematurely with _kCFStreamErrorCodeKey=60

Viewed 932

I have working code using a URLSession. I'm testing behaviour when the server does not respond and a request times out. I cannot make my request timeout greater than about 25 seconds.

let session: URLSession = {
    let config = URLSessionConfiguration.default
    config.timeoutIntervalForRequest = <various values in seconds I fill in>
    return URLSession(configuration: config)
}()

If I set timeoutIntervalForRequest=5 or 10 the request times out in 5 or 10 seconds and I see this EXPECTED error:

Error : Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo={NSUnderlyingError=0x15e6d1020 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 "(null)" UserInfo={_kCFStreamErrorCodeKey=-2102, _kCFStreamErrorDomainKey=4}}, NSErrorFailingURLStringKey=http://10.0.0.91:8084/margtest1/DatabaseServlet, NSErrorFailingURLKey=http://10.0.0.91:8084/margtest1/DatabaseServlet, _kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-2102, NSLocalizedDescription=The request timed out.}

If I set timeoutIntervalForRequest=60 (or more) about 25 seconds after the request I see this error log:

Error : Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo={NSUnderlyingError=0x12d896d50 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 "(null)" UserInfo={_kCFStreamErrorCodeKey=60, _kCFStreamErrorDomainKey=1}}, NSErrorFailingURLStringKey=http://10.0.0.91:8084/margtest1/DatabaseServlet, NSErrorFailingURLKey=http://10.0.0.91:8084/margtest1/DatabaseServlet, _kCFStreamErrorCodeKey=60, NSLocalizedDescription=The request timed out.}

CloudSync db DL failed. Sync failed.

The difference between these logs is that when the request times out earlier than timeoutIntervalForRequest I receive _kCFStreamErrorCodeKey=60. The NSUnderlyingError is also different.

To recap, my requests time out within about 25 seconds even when I set timeoutIntervalForRequest > 25. When this happens I see -kCFStreamErrorCodeKey=60.

I've spent a couple of hours internet searching for an explanation or way to debug this. Can you suggest how to fix this or a method to debug such an issue? Thanks in advance!

0 Answers
Related