Implemented Network API, now seeing tons of Network.NWError error 0 messages

Hi All,

We have recently implemented the Network API for TLS in lieu of CocoaAsyncSocket, and our connection seems steady for long periods of time, until we start receiving a flood of error messages that I can't find any documentation or evidence for online either in Apple docs or Stack or etc.

Does anyone have any insight into what Network.NWError error 0 entails?

I will include some sample logs below to illustrate just how frequently we are seeing this within a small time frame.

2021-08-19 06:11:48.898 MST Debug - [ns:AppDelegate] [[[[["NTWK: Closing..."]]]]] close(shouldAutoReconnect:)@185::<PrivoroTCP.PrivoroTCPClient: 0x283935110>
2021-08-19 06:11:48.898 MST Debug - [ns:AppDelegate] [[[[["NTWK: Receive Fail"]]]]] setupReceive()@266::<PrivoroTCP.PrivoroTCPClient: 0x283935110>
2021-08-19 06:11:48.899 MST Debug - [ns:AppDelegate] [[[[["NTWK: TCP socketDidDisconnect error: The operation couldn’t be completed. (Network.NWError error 0.)"]]]]] connectionDidFail(error:)@277::<PrivoroTCP.PrivoroTCPClient: 0x283935110>
2021-08-19 06:11:48.900 MST Debug - [ns:AppDelegate] [[[[["NTWK: Closing..."]]]]] close(shouldAutoReconnect:)@185::<PrivoroTCP.PrivoroTCPClient: 0x283935110>
2021-08-19 06:11:48.900 MST Debug - [ns:AppDelegate] [[[[["NTWK: Receive Fail"]]]]] setupReceive()@266::<PrivoroTCP.PrivoroTCPClient: 0x283935110>
2021-08-19 06:11:48.901 MST Debug - [ns:AppDelegate] [[[[["NTWK: TCP socketDidDisconnect error: The operation couldn’t be completed. (Network.NWError error 0.)"]]]]] connectionDidFail(error:)@277::<PrivoroTCP.PrivoroTCPClient: 0x283935110>
2021-08-19 06:11:48.902 MST Debug - [ns:AppDelegate] [[[[["NTWK: Closing..."]]]]] close(shouldAutoReconnect:)@185::<PrivoroTCP.PrivoroTCPClient: 0x283935110>
2021-08-19 06:11:48.903 MST Debug - [ns:AppDelegate] [[[[["NTWK: Receive Fail"]]]]] setupReceive()@266::<PrivoroTCP.PrivoroTCPClient: 0x283935110>
2021-08-19 06:11:48.903 MST Debug - [ns:AppDelegate] [[[[["NTWK: TCP socketDidDisconnect error: The operation couldn’t be completed. (Network.NWError error 0.)"]]]]] connectionDidFail(error:)@277::<PrivoroTCP.PrivoroTCPClient: 0x283935110>
2021-08-19 06:11:48.904 MST Debug - [ns:AppDelegate] [[[[["NTWK: Closing..."]]]]] close(shouldAutoReconnect:)@185::<PrivoroTCP.PrivoroTCPClient: 0x283935110>
2021-08-19 06:11:48.905 MST Debug - [ns:AppDelegate] [[[[["NTWK: Receive Fail"]]]]] setupReceive()@266::<PrivoroTCP.PrivoroTCPClient: 0x283935110>
2021-08-19 06:11:48.905 MST Debug - [ns:AppDelegate] [[[[["NTWK: TCP socketDidDisconnect error: The operation couldn’t be completed. (Network.NWError error 0.)"]]]]] connectionDidFail(error:)@277::<PrivoroTCP.PrivoroTCPClient: 0x283935110>
2021-08-19 06:11:48.906 MST Debug - [ns:AppDelegate] [[[[["NTWK: Closing..."]]]]] close(shouldAutoReconnect:)@185::<PrivoroTCP.PrivoroTCPClient: 0x283935110>
2021-08-19 06:11:48.907 MST Debug - [ns:AppDelegate] [[[[["NTWK: Receive Fail"]]]]] setupReceive()@266::<PrivoroTCP.PrivoroTCPClient: 0x283935110>
2021-08-19 06:11:48.908 MST Debug - [ns:AppDelegate] [[[[["NTWK: TCP socketDidDisconnect error: The operation couldn’t be completed. (Network.NWError error 0.)"]]]]] connectionDidFail(error:)@277::<PrivoroTCP.PrivoroTCPClient: 0x283935110>
2021-08-19 06:11:48.908 MST Debug - [ns:AppDelegate] [[[[["NTWK: Closing..."]]]]] close(shouldAutoReconnect:)@185::<PrivoroTCP.PrivoroTCPClient: 0x283935110>
2021-08-19 06:11:48.909 MST Debug - [ns:AppDelegate] [[[[["NTWK: Receive Fail"]]]]] setupReceive()@266::<PrivoroTCP.PrivoroTCPClient: 0x283935110>
2021-08-19 06:11:48.910 MST Debug - [ns:AppDelegate] [[[[["NTWK: TCP socketDidDisconnect error: The operation couldn’t be completed. (Network.NWError error 0.)"]]]]] connectionDidFail(error:)@277::<PrivoroTCP.PrivoroTCPClient: 0x283935110>
2021-08-19 06:11:48.911 MST Debug - [ns:AppDelegate] [[[[["NTWK: Closing..."]]]]] close(shouldAutoReconnect:)@185::<PrivoroTCP.PrivoroTCPClient: 0x283935110>
2021-08-19 06:11:48.911 MST Debug - [ns:AppDelegate] [[[[["NTWK: Receive Fail"]]]]] setupReceive()@266::<PrivoroTCP.PrivoroTCPClient: 0x283935110>
2021-08-19 06:11:48.912 MST Debug - [ns:AppDelegate] [[[[["NTWK: TCP socketDidDisconnect error: The operation couldn’t be completed. (Network.NWError error 0.)"]]]]] connectionDidFail(error:)@277::<PrivoroTCP.PrivoroTCPClient: 0x283935110>
2021-08-19 06:11:48.913 MST Debug - [ns:AppDelegate] [[[[["NTWK: Closing..."]]]]] close(shouldAutoReconnect:)@185::<PrivoroTCP.PrivoroTCPClient: 0x283935110>
2021-08-19 06:11:48.914 MST Debug - [ns:AppDelegate] [[[[["NTWK: Receive Fail"]]]]] setupReceive()@266::<PrivoroTCP.PrivoroTCPClient: 0x283935110>
2021-08-19 06:11:48.914 MST Debug - [ns:AppDelegate] [[[[["NTWK: TCP socketDidDisconnect error: The operation couldn’t be completed. (Network.NWError error 0.)"]]]]] connectionDidFail(error:)@277::<PrivoroTCP.PrivoroTCPClient: 0x283935110>
2021-08-19 06:11:48.915 MST Debug - [ns:AppDelegate] [[[[["NTWK: Closing..."]]]]] close(shouldAutoReconnect:)@185::<PrivoroTCP.PrivoroTCPClient: 0x283935110>
2021-08-19 06:11:48.916 MST Debug - [ns:AppDelegate] [[[[["NTWK: Receive Fail"]]]]] setupReceive()@266::<PrivoroTCP.PrivoroTCPClient: 0x283935110>
2021-08-19 06:11:48.917 MST Debug - [ns:AppDelegate] [[[[["NTWK: TCP socketDidDisconnect error: The operation couldn’t be completed. (Network.NWError error 0.)"]]]]] connectionDidFail(error:)@277::<PrivoroTCP.PrivoroTCPClient: 0x283935110>

Thanks for any help!

Based on these logs so close together:

2021-08-19 06:11:48.898 MST Debug - [ns:AppDelegate] [[[[["NTWK: Closing..."]]]]] close(shouldAutoReconnect:)@185::<PrivoroTCP.PrivoroTCPClient: 0x283935110>
2021-08-19 06:11:48.898 MST Debug - [ns:AppDelegate] [[[[["NTWK: Receive Fail"]]]]] setupReceive()@266::<PrivoroTCP.PrivoroTCPClient: 0x283935110>
2021-08-19 06:11:48.899 MST Debug - [ns:AppDelegate] [[[[["NTWK: TCP socketDidDisconnect error: The operation couldn’t be completed. (Network.NWError error 0.)"]]]]] connectionDidFail(error:)@277::<PrivoroTCP.PrivoroTCPClient: 0x283935110>

It looks like your NWConenction is closing and then trying to auto-reconnect right away with setupReceive called immediately with the failure for Network.NWError error 0 coming shortly after that.

Now, if you wait for your connection to go into the .ready state and then call setupReceive, does this still happen?

Regarding:

Does anyone have any insight into what Network.NWError error 0 entails?

This looks just like a generic error indicating that there was an issue. Some error codes for NWError can fit nicely into POSIX mapped codes, but 0 just looks like a generic issue, and the same goes for "The operation couldn’t be completed," as well.

Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com
Implemented Network API, now seeing tons of Network.NWError error 0 messages
 
 
Q