NWBrowser retains stale info after disconnecting cable

My app uses NWBrowser and NWListener to advertise a service and to discover other peer instances on the local network. It regenerates a serial number with each fresh launch. This serial number is included in TXTRecord. I can see that the serial number correctly changes after every restart.

The problem that is bugging me right now is as follows. If I run the app with the lightning cable connected to my Macbook and then disconnect the cable, the app running on my IPhone would retain the information about my Macbook no matter how many times I restart the app or restart the other peer. It doesn't matter if I close the app before disconnecting the cable or the other way around.

Restarting the app on my Macbook while in this state doesn't refresh the record on my IPhone. The app is supposed to replace the found instances for new and change cases but the old instance always prevails.

I even went into airplane mode and turned off everything wireless on both my IPhone and my macbook. Nothing but services previously advertised by my Macbook still show up, which includes _airplay._tcp

A third-party app for Bonjour discovery also confirms the phantom instances but it was of course unable to resolve these instances. It always takes tens of minutes for the phantom instances to be removed short of a reboot.

I then discovered that if I start the app without the lightening cable connected, this issue wouldn't happen anymore. This suggests to me that this may have to do with the lightning port's network.

The same app (via Mac Catalyst) running on the Macbook does not have this issue.

Has anyone experienced anything similar?

Problems like this are common in Bonjour due to its underlying technology [1]. Specifically, mDNS requires that each peer maintain a distributed database of local DNS records. That involves a trade-off between consistency and network traffic, and mDNS tends to err on the side of reducing network traffic.

However, the specific case you’ve mentioned is interesting. When you disconnect a physical interface the system knows that any records associated with that interface are no longer relevant. This path is commonly exercised for other wired interfaces, most notably Ethernet. It seems that there’s something Lightning specific going on.

With NWBrowser the browseResultsChangedHandler callback gets both the current state (newResults) and deltas (changes). Which are you working from?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Bonjour is Apple’s term for:

NWBrowser retains stale info after disconnecting cable
 
 
Q