Skip to content

fix: gateway robustness — re-detect on user actions and VPN interface changes#10

Merged
GeiserX merged 2 commits intomainfrom
fix/gateway-robustness
Feb 25, 2026
Merged

fix: gateway robustness — re-detect on user actions and VPN interface changes#10
GeiserX merged 2 commits intomainfrom
fix/gateway-robustness

Conversation

@GeiserX
Copy link
Owner

@GeiserX GeiserX commented Feb 25, 2026

Summary

  • Fresh gateway on user actions: addDomain, toggleDomain, toggleService, retryFailedDomain, setAllDomainsEnabled, and setAllServicesEnabled now call ensureGateway() inside their async Tasks, re-detecting the gateway if it's nil instead of silently skipping route application
  • VPN interface change handling: checkVPNStatus now detects when VPN stays connected but switches interfaces (e.g., utun4 → utun5) and automatically re-applies all routes through the new gateway
  • NWPathMonitor tracks interface names: Catches utun interface switches that type-only comparison (Set<NWInterface.InterfaceType>) missed, since all utun interfaces are .other
  • No silent failures: All gateway-nil code paths now log explicit errors instead of silently skipping

Problem

When VPN switched interfaces (common with GlobalProtect reconnects), localGateway became stale/nil. Adding a domain would save it to config but silently skip route application — the user saw the domain in the list and assumed it was bypassing VPN. The only workaround was manually clicking "Refresh Routes".

Test plan

  • Add domain while VPN is connected — routes applied immediately
  • Add domain after VPN reconnects on different interface — routes still applied (gateway re-detected)
  • Toggle domain on/off — routes added/removed correctly
  • VPN interface change while connected — routes automatically re-applied
  • Logs show explicit errors when gateway is nil (no silent skips)
  • Release build succeeds

Gateway was stale when VPN switched interfaces (e.g. utun4 → utun5),
causing addDomain/toggleDomain to silently skip route application.
Now all user-triggered actions re-detect the gateway if nil, VPN
interface changes trigger automatic re-routing, and NWPathMonitor
tracks interface names (not just types) to catch utun transitions.
- Reset lastInterfaceNames in restartNetworkMonitor() (was missing after PR addition)
- Fix data race on networkDebounceWorkItem by moving access to main thread
- Guard interface != nil in VPN switch handler to prevent spurious re-routes
- Make ensureGateway() time-aware (re-detect if >10s stale, not just nil)
- Add 10s cooldown for VPN interface flapping to prevent rapid re-route storms
- Validate gateway as IPv4 in getGatewayForService and parseDefaultGateway
- Replace isApplyingRoutes Bool with ref-counted begin/endApplyingRoutes()
- Replace force-unwrap in ensureGateway() with safe if-let binding
- Bump CFBundleVersion to 20
- Revert Cask version to 1.8.0 (let make full-release handle version+SHA atomically)
@GeiserX GeiserX merged commit a97c9d4 into main Feb 25, 2026
3 checks passed
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.

1 participant