[PR #3346] fix(macos): restore VPN DNS after network changes #3217

Open
opened 2026-10-30 04:58:04 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/amnezia-vpn/amnezia-client/pull/3346
Author: @alexalok
Created: 10/28/2026
Status: 🔄 Open

Base: dev ← Head: alex/macos-dns-recovery


📝 Commits (2)

  • d49ca71 fix(macos): restore VPN DNS after network changes
  • 6fb96c0 fix(macos): retain DNS subscription across reconnects

📊 Changes

6 files changed (+589 additions, -23 deletions)

View changed files

📝 client/platforms/macos/daemon/dnsutilsmacos.cpp (+166 -21)
📝 client/platforms/macos/daemon/dnsutilsmacos.h (+14 -2)
➕ tests/macosdns/CMakeLists.txt (+38 -0)
➕ tests/macosdns/README.md (+29 -0)
➕ tests/macosdns/support/logger.h (+10 -0)
➕ tests/macosdns/tst_macosdns.cpp (+332 -0)

📄 Description

Problem

The standalone macOS client writes VPN DNS into Setup:/Network/Service/<UUID>/DNS at connection time. When macOS refreshes network configuration and removes or replaces that override, the AWG/WireGuard tunnel can remain connected while applications use DHCP DNS. No DNS-change listener reapplies the VPN settings.

This addresses the DNS-loss case reported in this comment on #3267. It does not address the separate gateway/ARP failure in the original report.

Change

  • Subscribe to network-service and DNS keys once per DNS utility lifetime, and repair only while the VPN DNS override is active. Deliver native notifications to the Qt object thread through a serial dispatch queue.
  • Reapply the desired DNS only when it differs, including for newly added services. Keep the original backup across repairs and repeated updates.
  • Disable repair before restoration, invalidate queued work across reconnects, and retain callback context independently of object lifetime. Cancel the native subscription only at destruction: immediate unsubscribe/resubscribe can fail while asynchronous cancellation is still pending.
  • Report registration/read/write failures; distinguish missing keys from read errors and preserve failed restoration backups for retry. Do not recreate removed services.
  • Add a standalone macOS QtTest suite that compiles the production DNS class, using an in-memory SystemConfiguration boundary without changing host DNS.

Validation

On Apple silicon, macOS 26.6.2, Xcode 27.1, Qt 6.11.2:

  • Original code reproduced deletion recovery, backup corruption, and failure-reporting regressions before the fix.
  • Standalone QtTest suite: 21 passed, 0 failed (19 scenarios plus initialization/cleanup).
  • Same suite passed with AddressSanitizer and UndefinedBehaviorSanitizer.
  • A read-only native SystemConfiguration probe reproduced kSCStatusNotifierActive on the second immediate subscribe/unsubscribe cycle. The follow-up regression models pending cancellation and passes with the lifetime subscription.
  • Changed production source and MOC compiled against real SystemConfiguration declarations and the production logger, without test API redirects.
  • git diff --check passed.

Reproduction commands and coverage: tests/macosdns/README.md.

Full application/test configuration was attempted but stopped because Conan is not installed. The existing QString::fromUtf16(UniChar*) deprecation warning remains unchanged. No replacement service was installed or restarted; actual configd event delivery and USB/DHCP/sleep/Wi-Fi recovery still need end-to-end validation with a built service. The tests prove recovery/lifecycle logic, not installed-app behavior.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/amnezia-vpn/amnezia-client/pull/3346 **Author:** [@alexalok](https://github.com/alexalok) **Created:** 10/28/2026 **Status:** 🔄 Open **Base:** `dev` ← **Head:** `alex/macos-dns-recovery` --- ### 📝 Commits (2) - [`d49ca71`](https://github.com/amnezia-vpn/amnezia-client/commit/d49ca71c99f4fc65573cfb7fb14a37a24d56f0dd) fix(macos): restore VPN DNS after network changes - [`6fb96c0`](https://github.com/amnezia-vpn/amnezia-client/commit/6fb96c0886b6f4bf8765fe6337661f45f2b2e617) fix(macos): retain DNS subscription across reconnects ### 📊 Changes **6 files changed** (+589 additions, -23 deletions) <details> <summary>View changed files</summary> 📝 `client/platforms/macos/daemon/dnsutilsmacos.cpp` (+166 -21) 📝 `client/platforms/macos/daemon/dnsutilsmacos.h` (+14 -2) ➕ `tests/macosdns/CMakeLists.txt` (+38 -0) ➕ `tests/macosdns/README.md` (+29 -0) ➕ `tests/macosdns/support/logger.h` (+10 -0) ➕ `tests/macosdns/tst_macosdns.cpp` (+332 -0) </details> ### 📄 Description ## Problem The standalone macOS client writes VPN DNS into `Setup:/Network/Service/<UUID>/DNS` at connection time. When macOS refreshes network configuration and removes or replaces that override, the AWG/WireGuard tunnel can remain connected while applications use DHCP DNS. No DNS-change listener reapplies the VPN settings. This addresses the DNS-loss case reported in [this comment on #3267](https://github.com/amnezia-vpn/amnezia-client/issues/3267#issuecomment-6070869518). It does not address the separate gateway/ARP failure in the original report. ## Change - Subscribe to network-service and DNS keys once per DNS utility lifetime, and repair only while the VPN DNS override is active. Deliver native notifications to the Qt object thread through a serial dispatch queue. - Reapply the desired DNS only when it differs, including for newly added services. Keep the original backup across repairs and repeated updates. - Disable repair before restoration, invalidate queued work across reconnects, and retain callback context independently of object lifetime. Cancel the native subscription only at destruction: immediate unsubscribe/resubscribe can fail while asynchronous cancellation is still pending. - Report registration/read/write failures; distinguish missing keys from read errors and preserve failed restoration backups for retry. Do not recreate removed services. - Add a standalone macOS QtTest suite that compiles the production DNS class, using an in-memory SystemConfiguration boundary without changing host DNS. ## Validation On Apple silicon, macOS 26.6.2, Xcode 27.1, Qt 6.11.2: - Original code reproduced deletion recovery, backup corruption, and failure-reporting regressions before the fix. - Standalone QtTest suite: **21 passed, 0 failed** (19 scenarios plus initialization/cleanup). - Same suite passed with **AddressSanitizer and UndefinedBehaviorSanitizer**. - A read-only native SystemConfiguration probe reproduced `kSCStatusNotifierActive` on the second immediate subscribe/unsubscribe cycle. The follow-up regression models pending cancellation and passes with the lifetime subscription. - Changed production source and MOC compiled against real SystemConfiguration declarations and the production logger, without test API redirects. - `git diff --check` passed. Reproduction commands and coverage: `tests/macosdns/README.md`. Full application/test configuration was attempted but stopped because Conan is not installed. The existing `QString::fromUtf16(UniChar*)` deprecation warning remains unchanged. No replacement service was installed or restarted; actual configd event delivery and USB/DHCP/sleep/Wi-Fi recovery still need end-to-end validation with a built service. The tests prove recovery/lifecycle logic, not installed-app behavior. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
amnezia-vpn/amnezia-client#3217
No description provided.