[PR #3114] fix(windows): eliminate route-change storms with large split-tunnel e… #3086

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

📋 Pull Request Information

Original PR: https://github.com/amnezia-vpn/amnezia-client/pull/3114
Author: @hgminusone
Created: 9/1/2026
Status: 🔄 Open

Base: dev ← Head: fix/win-split-tunnel-route-storm


📝 Commits (1)

  • bb106e5 fix(windows): eliminate route-change storms with large split-tunnel exclusion lists

📊 Changes

7 files changed (+243 additions, -61 deletions)

View changed files

📝 client/daemon/daemon.cpp (+44 -11)
📝 client/daemon/daemon.h (+1 -0)
📝 client/daemon/wireguardutils.h (+18 -0)
📝 client/platforms/windows/daemon/windowsroutemonitor.cpp (+166 -50)
📝 client/platforms/windows/daemon/windowsroutemonitor.h (+2 -0)
📝 client/platforms/windows/daemon/wireguardutilswindows.cpp (+10 -0)
📝 client/platforms/windows/daemon/wireguardutilswindows.h (+2 -0)

📄 Description

…xclusion lists

Importing a large IP exclusion list (~8.6k prefixes) made the Windows client unusable: connecting stalled for many minutes, disconnecting hung, and after a forced kill the client could not reconnect until reboot.

Three related defects in WindowsRouteMonitor:

  1. Quadratic route installation. Every added exclusion route refetched the full routing table and interface metrics. Measured on stock: 500 prefixes = 1.4s, 1000 = 6.4s, 2000 = 33.4s (the kernel itself installs 500 routes in 146ms). Fix: batched add/delete entry points that snapshot the table once per address family; the teardown loop additionally refetched the table per deleted prefix.

  2. Self-sustaining rescan storm. The monitor subscribes to NotifyRouteChange2, but its own rescan rewrites routes (captured clones, flapping next-hops), waking itself: with a large list the monitor rescanned ~4 times/second for the whole session, starving the IPC queue (deactivate took minutes to be processed). The callback filter cannot drop these notifications because the notification rows carry unreliable Protocol/Metric fields. Fix: unsubscribe for the duration of bulk operations and of the rescan itself, then run exactly one manual rescan; real network changes still trigger it via the restored subscription.

  3. Orphaned exclusion routes. After a hard service kill the routes stayed in the system table pointing at the dead tunnel's next-hop, blackholing matching traffic (including the VPN server handshake) until reboot. Fix: purge NETMGMT+EXCLUSION_ROUTE_METRIC rows at monitor creation - that pair is only ever produced by this code.

Result with an 8658-prefix list: connect in 4-7s (route installation 0.85s), idle monitor after connect, teardown in seconds, reboot no longer needed after a crash.


🔄 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/3114 **Author:** [@hgminusone](https://github.com/hgminusone) **Created:** 9/1/2026 **Status:** 🔄 Open **Base:** `dev` ← **Head:** `fix/win-split-tunnel-route-storm` --- ### 📝 Commits (1) - [`bb106e5`](https://github.com/amnezia-vpn/amnezia-client/commit/bb106e5077c63e3bc9669927462f0fb2978a020e) fix(windows): eliminate route-change storms with large split-tunnel exclusion lists ### 📊 Changes **7 files changed** (+243 additions, -61 deletions) <details> <summary>View changed files</summary> 📝 `client/daemon/daemon.cpp` (+44 -11) 📝 `client/daemon/daemon.h` (+1 -0) 📝 `client/daemon/wireguardutils.h` (+18 -0) 📝 `client/platforms/windows/daemon/windowsroutemonitor.cpp` (+166 -50) 📝 `client/platforms/windows/daemon/windowsroutemonitor.h` (+2 -0) 📝 `client/platforms/windows/daemon/wireguardutilswindows.cpp` (+10 -0) 📝 `client/platforms/windows/daemon/wireguardutilswindows.h` (+2 -0) </details> ### 📄 Description …xclusion lists Importing a large IP exclusion list (~8.6k prefixes) made the Windows client unusable: connecting stalled for many minutes, disconnecting hung, and after a forced kill the client could not reconnect until reboot. Three related defects in WindowsRouteMonitor: 1. Quadratic route installation. Every added exclusion route refetched the full routing table and interface metrics. Measured on stock: 500 prefixes = 1.4s, 1000 = 6.4s, 2000 = 33.4s (the kernel itself installs 500 routes in 146ms). Fix: batched add/delete entry points that snapshot the table once per address family; the teardown loop additionally refetched the table per deleted prefix. 2. Self-sustaining rescan storm. The monitor subscribes to NotifyRouteChange2, but its own rescan rewrites routes (captured clones, flapping next-hops), waking itself: with a large list the monitor rescanned ~4 times/second for the whole session, starving the IPC queue (deactivate took minutes to be processed). The callback filter cannot drop these notifications because the notification rows carry unreliable Protocol/Metric fields. Fix: unsubscribe for the duration of bulk operations and of the rescan itself, then run exactly one manual rescan; real network changes still trigger it via the restored subscription. 3. Orphaned exclusion routes. After a hard service kill the routes stayed in the system table pointing at the dead tunnel's next-hop, blackholing matching traffic (including the VPN server handshake) until reboot. Fix: purge NETMGMT+EXCLUSION_ROUTE_METRIC rows at monitor creation - that pair is only ever produced by this code. Result with an 8658-prefix list: connect in 4-7s (route installation 0.85s), idle monitor after connect, teardown in seconds, reboot no longer needed after a crash. --- <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#3086
No description provided.