Linux: NetworkManager CONNECTED_GLOBAL transition causes unnecessary full VPN reconnect
Linux: NetworkManager CONNECTED_GLOBAL transition causes unnecessary full VPN reconnect and recreates tun2
Describe the bug
On Linux, AmneziaVPN performs a full VPN reconnect whenever NetworkManager emits:
StateChanged(NM_STATE_CONNECTED_GLOBAL = 70)even when the physical network, Wi-Fi access point, interface, and gateway have not actually changed.
A normal NetworkManager connectivity transition:
CONNECTED_GLOBAL -> CONNECTED_SITE -> CONNECTED_GLOBALis interpreted by AmneziaVPN as a network change.
When NetworkManager returns to CONNECTED_GLOBAL, AmneziaVPN calls VpnConnection::reconnectToVpn(). With Xray this stops Xray/tun2socks, destroys tun2, and creates a new tunnel.
In my case the event is triggered periodically by NetworkManager connectivity checks. The Wi-Fi access point does not change.
The unnecessary reconnect is disruptive by itself, but the reconnect cleanup also sometimes fails, leaving DNS/routes in a broken state until a manual VPN reconnect.
Environment
- OS: Ubuntu 25.10
- Kernel: Linux 6.17.0-41-generic
- Network manager: NetworkManager
- VPN protocol: Xray
- Xray data path:
tun2+tun2socks - TUN address:
10.33.0.2/24 - Physical connection remains active during the reproduced event
Reproduced timeline
Incident captured on 2026-08-31.
NetworkManager changes connectivity classification
16:30:05.947 DNS query: connectivity-check.ubuntu.com A
16:30:06.312 DNS reply: NOERROR
16:30:06.628 NetworkManager state is now CONNECTED_SITE
16:30:06.xxx Amnezia LinuxNetworkWatcherWorker: NMStateChanged 60NetworkManager then retries connectivity checks.
Approximately 31 seconds later:
16:30:37.338 DNS reply: NOERROR
16:30:37.657 NetworkManager state is now CONNECTED_GLOBAL
16:30:37.658 Amnezia LinuxNetworkWatcherWorker:
Properties changed for interface org.freedesktop.NetworkManager.Device
16:30:37.658 Amnezia LinuxNetworkWatcherWorker:
Access point did not changed. Ignoring the changes
16:30:37.658 Amnezia LinuxNetworkWatcherWorker:
NMStateChanged 70The important part is that AmneziaVPN itself reports that the access point did not change.
AmneziaVPN immediately reconnects
Immediately after NMStateChanged 70:
AmneziaVPN.desktop:
Reconnect triggered. Reconnecting to the server
AmneziaVPN.desktop:
XrayProtocol::stop()The existing TUN is then removed:
NetworkManager:
device (tun2): state change: activated -> unmanaged
(reason 'unmanaged', managed-type: 'removed')
AmneziaVPN-service:
deleteTun ret 0The diagnostic bundle independently confirms that the TUN FD was owned by Amnezia's tun2socks process.
Cleanup errors
During this automatic reconnect the logs also contain:
Failed to delete tun
No suitable DNS manager found.
VpnConnection::onConnectionStateChanged: Failed to flush DNS
Failed to clear saved routesand several route deletion failures.
A pkill invocation also reports:
pkill: pattern that searches for process name longer than 15 characters
will result in zero matches
Try `pkill -f' ...Tunnel is recreated
AmneziaVPN then starts Xray/tun2socks again and creates a new TUN:
XrayProtocol::start()
Xray::startXray()
tun2socks -device tun://tun2 -proxy socks5://127.0.0.1:...
ip tuntap add mode tun dev tun2
ip addr add 10.33.0.2/24 dev tun2
ip link set dev tun2 upTherefore the tun2 deletion is not caused by NetworkManager. NetworkManager observes the externally managed interface disappearing.
The tunnel is deliberately torn down by AmneziaVPN as part of reconnectToVpn().
Source-code cause
Current Linux code in:
client/platforms/linux/linuxnetworkwatcherworker.cppcontains:
void LinuxNetworkWatcherWorker::NMStateChanged(quint32 state)
{
logger.debug() << "NMStateChanged " << state;
if (state == NM_STATE_ASLEEP || state == NM_STATE_DISABLED) {
emit wakeup();
} else if (state == NM_STATE_CONNECTED_GLOBAL) {
emit networkChanged();
}
}Therefore every NetworkManager transition to CONNECTED_GLOBAL becomes networkChanged().
LinuxNetworkWatcher forwards it:
connect(m_worker, &LinuxNetworkWatcherWorker::networkChanged, this,
[this]() { emit networkChanged(""); });The service exposes it through IPC:
connect(&m_networkWatcher, &NetworkWatcher::networkChanged,
&m_ipcServer, &IpcServer::networkChanged);and VpnConnection connects that directly to:
VpnConnection::reconnectToVpnreconnectToVpn() performs:
qDebug() << "Reconnect triggered. Reconnecting to the server";
setConnectionState(Vpn::ConnectionState::Reconnecting);
m_vpnProtocol->stop();
m_vpnProtocol->start();The effective Linux behavior is therefore:
NetworkManager CONNECTED_GLOBAL
↓
networkChanged()
↓
VpnConnection::reconnectToVpn()
↓
stop VPN
↓
destroy tun2
↓
start VPN
↓
create new tun2But CONNECTED_GLOBAL is a NetworkManager connectivity classification, not proof that the underlying network changed.
Regression history
This behavior appears to have been introduced by:
PR #2415:
https://github.com/amnezia-vpn/amnezia-client/pull/2415
Commit:
ebe3a5dac6ae7101cb7e9520903ce92a0d1ed32e
fix: add linux reconnection (#2415)That change added:
else if (state == NM_STATE_CONNECTED_GLOBAL) {
emit networkChanged();
}There is also relevant earlier history.
Commit:
911a999c64b1bf107645cd4c5b1f4eee372c3914contained:
fix: remove network watcher due to its fragilenessThe watcher was subsequently restored and Linux reconnection behavior was added again.
Why this is not a real network change
At the exact triggering timestamp AmneziaVPN logs:
Access point did not changed. Ignoring the changes
NMStateChanged 70Therefore Amnezia's own AP detection says that the Wi-Fi network did not change.
The only relevant change is NetworkManager's global connectivity state returning from:
CONNECTED_SITEto:
CONNECTED_GLOBALPeriodic connectivity-check.ubuntu.com checks are visible immediately around these transitions.
Even if NetworkManager is completely correct to change its connectivity classification, AmneziaVPN should not equate every transition to CONNECTED_GLOBAL with a physical network change.
Expected behavior
A pure connectivity-classification transition:
CONNECTED_SITE -> CONNECTED_GLOBALmust not cause a full VPN reconnect by itself.
Reconnect should happen when there is evidence of a real underlying-network change, for example:
- physical interface changed;
- active NetworkManager connection changed;
- Wi-Fi AP/BSSID changed;
- default gateway changed;
- system resumed from suspend;
- previous physical connection disappeared;
- VPN data plane actually failed.
NetworkManager Internet-connectivity classification should not be used as a substitute for these checks.
Suggested fix
Please do not use:
state == NM_STATE_CONNECTED_GLOBALby itself as the condition for networkChanged().
A robust implementation could compare a physical-network identity tuple before reconnecting, for example:
physical interface
active connection
gateway
Wi-Fi BSSID where applicableand emit networkChanged() only when that identity actually changes.
Alternatively, listen to NetworkManager active-connection/device changes rather than its global Internet-connectivity classification.
Wakeup handling should remain separate.
It would also be useful to debounce/deduplicate reconnect events while the connection is already reconnecting.
Additional problem exposed by the unnecessary reconnect
The automatic reconnect frequently reports cleanup failures:
Failed to flush DNS
Failed to clear saved routes
Failed to delete tunThis can leave the newly created tunnel in a partially broken state even though the application reports it as connected.
A manual Disconnect -> Connect can restore connectivity.
So eliminating false reconnects would prevent the immediate trigger, while cleanup/reconnect reliability should probably be investigated separately as well.
Source: amnezia-vpn/amnezia-client