iOS 11.4 Always getting NSURLErrorDomain Code=-1005 "The network connection was lost."

Hi Team,

I am using iOS 11.4 and hitting web service call but i am always getting status code 1005 when I lunch app first time. Here is my steps to reporduce the bug.


Note: I ahve added. setenv("CFNETWORK_DIAGNOSTICS", "3", 1); this line into main.m file



1. Launch the app

2. Provide UserName and Password for login into the app

3. After Receiving successful authentication hitting another api and mean while getting current location as well.

4. Location popup is coming and We choose Don't Allow and user is redicted to Settings screen to enable the current location allow and comming back to app and we are getting following error logs:



NSURLConnection finished with error - code -1005

-[NetworkManager connection:didFailWithError:] [Line 171] connection didFailWithError.. error code -1005 -- Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo={NSUnderlyingError=0x1c005c5c0 {Error Domain=kCFErrorDomainCFNetwork Code=-1005 "The network connection was lost." UserInfo={NSErrorFailingURLStringKey=https://dummyURL.com, _kCFStreamErrorDomainKey=4, NSErrorPeerAddressKey=<CFData 0x1cc09a9f0 [0x1b3b16538]>{length = 16, capacity = 16, bytes = 0x100201bb0a6c0e4d0000000000000000}, _kCFStreamErrorCodeKey=-4, NSErrorFailingURLKey=https://dummyURL.com, NSLocalizedDescription=The network connection was lost.}}, NSErrorFailingURLStringKey=https://dummyURL.com, NSErrorFailingURLKey=https://m.qa2-dfw.svbconnect.com/mp/api/1.0/users/notifications, _kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-4, NSLocalizedDescription=The network connection was lost.}



CFNetwork Diagnostics [3:1099] {

destroyReadStream: request POST https://dummyURL.com HTTP/1.1

Request: <CFURLRequest 0x1c41b6420 [0x1b3b16538]> {url = https://dummyURL.com, cs = 0x0}

sent: <CFNumber 0xb0000000000040a3 [0x1b3b16538]>{value = +1034, type = kCFNumberSInt64Type}

received: <CFNumber 0xb000000000000003 [0x1b3b16538]>{value = +0, type = kCFNumberSInt64Type}

cell sent: <CFNumber 0xb000000000000003 [0x1b3b16538]>{value = +0, type = kCFNumberSInt64Type}

cell received: <CFNumber 0xb000000000000003 [0x1b3b16538]>{value = +0, type = kCFNumberSInt64Type}

} [3:1099]

[425:29989] CFNetwork Diagnostics [3:1100] {

~HTTPProtocol: nullptr request

Request: null

sent: 1034

received: 0

cell sent: 0

cell received: 0

} [3:1100]

[425:29991] -[NetworkManager dealloc] [Line 270] dealloc NetworkManager

[425:30056] CFNetwork Diagnostics [3:1101] {

DiskCookieStorage Sync Request: (null)

Forced: no

isDirty: yes

isWriting: no

File: <CFURL 0x1cc0a9d80 [0x1b3b16538]>{string = file:///private/var/mobile/Containers/Data/Application/00925388-3D38-43CE-AF1F-55A0276808D2/Library/Cookies/Cookies.binarycookies, encoding = 134217984, base = (null)}

Journal: yes

Mutations: 13

} [3:1101]

[425:30056] CFNetwork Diagnostics [3:1102] {

DiskCookieStorage Checking: Binary{ Disk Cookies: { /private/var/mobile/Containers/Data/Application/00925388-3D38-43CE-AF1F-55A0276808D2/Library/Cookies/Cookies.binarycookies, <8 cookies in 2 domains> dirty not writing } }

File: <CFURL 0x1cc0a9d80 [0x1b3b16538]>{string = file:///private/var/mobile/Containers/Data/Application/00925388-3D38-43CE-AF1F-55A0276808D2/Library/Cookies/Cookies.binarycookies, encoding = 134217984, base = (null)}

Disk Mod: 2018-07-03 07:40:00 +0000

Last Sync: 2018-07-03 07:40:00 +0000

Persistent Cookies: <1 cookies in 1 domains>

Session Cookies: <7 cookies in 1 domains>

Journal: not required

} [3:1102]

[425:29987] CFNetwork Diagnostics [3:1103] {

DiskCookieStorage Updated: Binary{ Disk Cookies: { /private/var/mobile/Containers/Data/Application/00925388-3D38-43CE-AF1F-55A0276808D2/Library/Cookies/Cookies.binarycookies, <8 cookies in 2 domains> dirty writing } }

Persistent Cookies: <1 cookies in 1 domains>

Session Cookies: <7 cookies in 1 domains>

Time from first dirty: 10.0123

Time from last dirty: 10.0121

Total time to write: 0.008039

} [3:1103]


Please do needful for me to findout what is the problem.

Replies

To start, please read QA1941 Handling “The network connection was lost” Errors to understand the background to this issue.

Given that that this problem reproduces every time, it warrants further investigation. My recommendation is that you look at a packet trace (see QA1176) to confirm that it is the server dropping the connection and, if so, see what’s different about this connection rather than subsequent connections that’s triggering the issue.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"