When to not restart on connectionStateChanged to .waiting()

The documentation seems to indicate that the extension should restart on waiting i.e.

``       private func connectionStateChanged(to state: NWConnection.State) {         switch state {   case .waiting(let error):

            os_log(.debug, log: self.log, "DNSProxyProvider Error opening connection -- waiting : (%{public}@)", error.localizedDescription)                 connection.restart() }

``

I sometimes find I get into a look when this happens

com.otg.titahHQ.OTGDNSProxy: [com.titanhq.otg.OTGDNSProxy:provider] DNSProxyProvider  connectionStateChanged to preparing

com.otg.titahHQ.OTGDNSProxy: [com.titanhq.otg.OTGDNSProxy:provider] DNSProxyProvider  connectionStateChanged to preparing

2021-10-27 15:54:18.214239+0100 0x1d7ca    Debug       0x0                  2300   0    com.otg.titahHQ.OTGDNSProxy: [com.titanhq.otg.OTGDNSProxy:provider] DNSProxyProvider  connectionStateChanged to preparing

2021-10-27 15:54:18.214696+0100 0x1d7ca    Debug       0x0                  2300   0    com.otg.titahHQ.OTGDNSProxy: [com.titanhq.otg.OTGDNSProxy:provider] DNSProxyProvider  connectionStateChanged to preparing

2021-10-27 15:54:18.215288+0100 0x1d7ca    Debug       0x0                  2300   0    com.otg.titahHQ.OTGDNSProxy: [com.titanhq.otg.OTGDNSProxy:provider] DNSProxyProvider Error opening connection -- waiting : (The operation couldn\U2019t be completed. (Network.NWError error 1.))

2021-10-27 15:54:18.215806+0100 0x1d7ca    Debug       0x0                  2300   0    com.otg.titahHQ.OTGDNSProxy: [com.titanhq.otg.OTGDNSProxy:provider] DNSProxyProvider Error opening connection -- waiting : (The operation couldn\U2019t be completed. (Network.NWError error 1.))

2021-10-27 15:54:18.216271+0100 0x1d7ca    Debug       0x0                  2300   0    com.otg.titahHQ.OTGDNSProxy: [com.titanhq.otg.OTGDNSProxy:provider] DNSProxyProvider Error opening connection -- waiting : (The operation couldn\U2019t be completed. (Network.NWError error 1.))

The network error here isn't very explanatory. My question is what to do here, if I get too many errors, should I cancel the connection or call flow.closeWithReadError, flow.closeWithWriteError

My question is what to do here, if I get too many errors, should I cancel the connection or call flow.closeWithReadError, flow.closeWithWriteError

If you go into .waiting with any of these connections with an error, I would try cancelling and retrying. If you get the same error, you may consider discarding the flow.

Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com

Hi @meaton

Sorry about the delay, do you mean to just cancel the connection and restart the connection.

if error != nil {    connection.cancel()     connection.restart() }

Sorry about the delay, do you mean to just cancel the connection and restart the connection.

Yes.

Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com
When to not restart on connectionStateChanged to .waiting()
 
 
Q