Skip to content

fix(apple): increase sensitivity of network reset - #9993

Merged
thomaseizinger merged 5 commits into
mainfrom
fix/reset-network-on-dns
Jul 24, 2025
Merged

fix(apple): increase sensitivity of network reset#9993
thomaseizinger merged 5 commits into
mainfrom
fix/reset-network-on-dns

Conversation

@jamilbk

@jamilbk jamilbk commented Jul 24, 2025

Copy link
Copy Markdown
Member

On Apple platforms, we tried to be clever about filtering path updates from the network connectivity change monitor, because there can be a flurry of them upon waking from sleep or network roaming.

However, because of this, we had a bug that could occur in certain situations (such as waking from sleep) where we could effectively "land" on an empty DNS resolver list. This could happen if:

  1. We receive a path update handler that meaningfully changes connectivity, but its supportsDNS property is false. This means it hasn't received any resolvers from DHCP yet. We would then setDns with an empty resolver list.
  2. We then receive a path update handler with the only change being supportDNS=true. Since we didn't count this change as a meaningful path change, we skipped the setDns call, and connlib would be stuck without DNS resolution.

To fix the above, we stop trying to be clever about connectivity changes, and just use oldPath != path. That will increase reset a bit, but it will now handle other edge cases such as an IP address changing on the primary interface, any other interfaces change, and the like.

Fixes #9866

@vercel

vercel Bot commented Jul 24, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
firezone ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 24, 2025 8:57pm

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug in Apple platform network connectivity handling where DNS resolution could fail after waking from sleep or network roaming. The fix simplifies the path update logic by removing the "clever" filtering that was causing edge cases.

  • Removed custom path comparison logic that filtered path updates based on specific properties
  • Simplified network reset to trigger on any path change rather than only "relevant" changes
  • Removed conditional DNS resolver fetching to ensure DNS is always updated on path changes

}

// Update our path tracker
self.lastPath = path

Copilot AI Jul 24, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lastPath variable is being set but never used for comparison. The code removes the path comparison logic but still tracks lastPath without utilizing it, which suggests incomplete refactoring or dead code.

Suggested change
self.lastPath = path

Copilot uses AI. Check for mistakes.
#endif

extension Network.NWPath {
func connectivityDifferentFrom(path: Network.NWPath) -> Bool {

@jamilbk jamilbk Jul 24, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alternative here is to add supportsDNS to the list of connectivity changes we care about. There are lots of other path properties whose changes I'm not sure we need to respond to. This is safer w.r.t. resets, but runs the risk of resetting too often.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I did the above here. Looks like many new properties are being added to the path struct here in macOS 26 that we won't want to act upon, like link quality changes.

if lastRelevantPath?.connectivityDifferentFrom(path: path) != false {
lastRelevantPath = path

session?.reset("primary network path changed")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

connlib will do this for you and no-op if they are unchanged. You can save on the JSON processing if you want but it is otherwise save to send the same list again.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I'll clean that up here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol, this comment is on the wrong line now? Pretty sure I commented on the DNS resolvers.

@thomaseizinger thomaseizinger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I think we need to err on the side of caution here and reset a bit too often rather than not enough.

if lastRelevantPath?.connectivityDifferentFrom(path: path) != false {
lastRelevantPath = path

session?.reset("primary network path changed")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol, this comment is on the wrong line now? Pretty sure I commented on the DNS resolvers.

@thomaseizinger
thomaseizinger added this pull request to the merge queue Jul 24, 2025
Merged via the queue into main with commit 67b4dd8 Jul 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DNS resolvers empty after wake from sleep

3 participants