[PATCH] wg-quick: darwin: ignore pending SIGALRM during monitor teardown
Alex Kearns-Apuya
alex at kearnsapuya.com
Thu Sep 24 16:21:36 UTC 2026
When DNS is configured, the route monitor subshell traps ALRM to
set_dns and, after every route event it handles, schedules
`sleep 2 && kill -ALRM $bpid` in the background. Its INT/TERM/EXIT trap
runs del_routes and del_dns but never disarms the ALRM handler, so if
the monitor handled a route event in the two seconds before teardown
(removing the interface generates route events of its own), the pending
ALRM is delivered while del_dns is restoring the network services.
set_dns then runs from the trap and re-pins every service to the
tunnel's DNS servers, leaving them pinned after the interface is gone.
Observed on macOS 27.2 with Homebrew wireguard-tools (the same code is
at current master) and a config with a DNS= line, sampling the
SystemConfiguration preferences at 10 Hz during `wg-quick down`: pinned
services went 6 -> 1 as del_dns ran, then back to 6 in set_dns order,
and 5 stayed pinned after the teardown finished. It reproduced on 1 of
2 controlled downs, plus one unprompted occurrence, and does not depend
on how `down` is invoked.
Ignore ALRM first thing in the exit trap. Resetting it with
`trap - ALRM` is not enough: SIGALRM's default action terminates the
subshell, which would abort the restore instead. With this change, 6 of
6 up/down cycles restored DNS, with the monitor still lingering
1.2-5.4 s past the interface teardown each time (the triggering
condition).
Configs without DNS= never install the ALRM trap and are unaffected.
Signed-off-by: Alex Kearns-Apuya <alex at kearnsapuya.com>
---
src/wg-quick/darwin.bash | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/wg-quick/darwin.bash b/src/wg-quick/darwin.bash
index 0179afb..20a21ce 100755
--- a/src/wg-quick/darwin.bash
+++ b/src/wg-quick/darwin.bash
@@ -323,7 +323,7 @@ del_dns() {
monitor_daemon() {
echo "[+] Backgrounding route monitor" >&2
- (trap 'del_routes; del_dns; exit 0' INT TERM EXIT
+ (trap 'trap "" ALRM; del_routes; del_dns; exit 0' INT TERM EXIT
exec >/dev/null 2>&1
exec 19< <(exec route -n monitor)
local event bpid=$BASHPID mpid=$!
--
2.54.0 (Apple Git-157)
More information about the WireGuard
mailing list