mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-12-03 19:50:19 +07:00
[PR #3327] feat: follow server IP changes behind the host name without a manual reconnect #3198
Open
opened 2026-10-27 06:18:54 +07:00 by bsakaguchi
·
0 comments
No Branch/Tag specified
dev
feat/pages-ui-tests
feat/otp-free-users-login
fix/refresh-external-ip-and-proxy-config-in-start-sh
fix/ios-keep-nav-bar-below-status-bar-and-lift-rename-sheet-over-keyboard
fix/ios-stop-hev-before-restarting-xray-tunnel
feat/whatsapp-proxy
fix/keep-socks-and-pfx-secrets-out-of-command-lines
fix/pass-the-tunnel-config-over-a-named-pipe
feat/test-xray-pages-ui
fix/expect-server-xray-v26.10.31
fix/align-xray-settings-with-core-defaults-and-add-contract-tests
feat/xtun
feat/separated-ui-models-and-controllers-tests
fix/keep-default-godebug-when-disabling-async-preemption
feat/otp-login
feat/android-tests
fix/server-removal-navigation-and-sheet-reopen
feat/add-deep-link
feat_copy_docker_configs
fix/gateway-requests-on-slow-or-blocked-dns
fix/bypass-proxy
feat/api-tests
fix/serialize-log-record-writes-and-pin-log-date-format-locale
fix/libagw-review-fixes
fix/ios-xray-ipv6-leak
fix/macos-xray-ipv6-leak
feat/add-support-include-split-tunnel
fix/win-xray-app-split-tunneling
fix/bug-when-saving-after-canceling
fix/xray-reconnect-crash
fix/share-empty-config-on-ssh-timeout
fix/ssh-credentials-input
fix/updater-verify-signature
fix/async-ssh-threading
fix/xray-check-inet-and-liveness-monitor
fix/selfhosted-server-installations
feat/add-support-ikev2-macos
fix/icons-different-color-themes
feat/add_support_arm_windows
feat/fixed-push-notifications-on-VPN-connect-disconnect-2
feat/implement-QR-code-generation-and-scanning
feat/file-password-protection
feat/add-support-split-tunnel-macos
feat/tests
fix/android-register-unacknowledged-purchase
fix/share_on_linux
mirroring-to-outside
feat/self-diagnostics-log
feat/amnezia-free-vless-switch
fix/conan_build_android_on_win
fix/linux-reconnect-dns-reliability
fix/windows-connection-stability
fix/linux-reconnect-refactoring
fix/ios-groupidentifier-order
feat/xray-subscription-link
fix/minor-fixes
fix/xray-config-inplace-edit
feat/amnezia-sdk-typed-api
feat/amnezia-sdk-integration
feat/force-update-native
refactor/marketplace-update-popup
feat/force-update
fix/valnurability_dev
chore-xcode-version
fix/empty-i1-i5
build_qt_6_10_1
master
feat/protocol-selection
fix/openvpn_install
feat/locations_change
feat/locations_change_rework
feature/local-proxy-integration
fix/filepicker_atv
fix_valnurability
fix/macos-ne-codesign-4.8.19.0
temp-branch-for-testing
fix/rebased_4_8_19_linux_fix_error
feat/proxy-storage-cache
fix/zeroed-params
fix/killswitch-blocknets-linux
update/translation_RU
fix/self_hosted_reinstall_error
feat/selfhosted-dns
fix/agp_version_up
feat/switch_to_alive_protocol
feat/support_multipeer
server_scripts_update
fix/extended-vless-configuration
chore/apple-ci-cd-macos-versions
feat/add-telemt
fix/android_keystore_read_error
feat/add-mtproxy
chore/bump-qt-version
fix/make_dbus_async
feature/dns
rebase/apple-tv-target-on-conan
fix/outbound_freedom_xray_with_dns_fix
feat/apk_support
feat/fallback-proxy
feat/apple-tv-target
fix/dns_reconnection_issue
feat/fixed-push-notifications-on-VPN-connect-disconnect
fix/linux-firewall
docker-regional-locks
appstore-review-popup
feat/storekit2
fix/uninstall-split-tunnelling-driver
revert-2376-chore/license-file
support_16kb_android
bump_version
feat_add_review_android
bugfix/translation-absence-on-subscription-key-page
feat/location-separation-by-region
bugfix/text-moving-when-resing-window
fix_backup
feature/add-purchase-android
bugfix/moved-text-while-resizing-window
bugfix/incorrect-killswitch-restore-from-backup
fix/backup-exclude-secondary-api-configs
feat/proxy-fields-for-dev-console
bugfix/ovpn-ios-fix
bugfix/linux-bundle-libraries
fix/xray-app-split-win
fix/upload-to-s3
chore/add-release-date-upload
feat_add_webview_support
feature/configuration-transfer-through-qr
feat/bot-key-unlink-device
fix/ad-link-lang-support
fix/qsecuresettings-with-android
feat/add-support-arm64-win
spanish-translations
fix/context-menu
feat/add-system-dns-support
fix/qt6-9-support
fix/qt6_9_support
bugfix/strict-killswitch-ui
android-7
chore/minor-bugfixes
feature/awg-net-fix-macos-wakeup
fixbug/ios18
bugfix/ios-ne-crash
fix/linux-tray-quit-button
cryptpad-support
bugfix/disable-linux-killswitch
fix/minor-ui-fixes
feature/setup-guid-tun2socks
feature/linux-ipsec
feature/ipsec-linux
refactoring/server-config-in-classes
feature/macos-ipsec
fix/ui-fixes-after-merge-with-d20ed4a
chore/focus_control_after_qt_6.9_migration
feature/integrate-xray-as-a-library
maxos-awg-fix
feature/add-new-awg-docker-image
chore/update-3rd-prebuild
feature/test-news
fix/api-conf-files
bugfix/split-tunneling-with-api-config
bugfix/ios-awg-new-fields
feature/special-handshake-2
feat/xray-api-support
fix/desktop-entry
bugfix/shadowsocks-cipher-setting-not-changing
feature/update-tap
bugfix/openvpn_import_fix
feature/ability-to-change-port-after-installing-xray
bugfix/strict-mode-ovpn
bugfix/win-ipv6-ovpn
bugfix/subnet-adress-setting
exception-podman-docker
bugfix/fix-listviewtype-scrolling
bugfix/win-disabled-ipv6
bugfix/win-ipv6-disabled-ovpn
feature/killswitch-strict-mode
feature/awg-network-check
feature/empty-split-tunneling-list
feature/support-info
chore/update-go-version
checking-Linux-version
update_server_scripts
bugfix/button-selection-easy-setup-page
feature/old-api-proxy
patch/user-checking
fix/correcting-version
support-podman
support_podman
user-checking-patch
feature/check-docker-version
feature/allowed-dns-list
without_lsof
chore/error-body
Update-amneziavpn_ru_RU
shiroow-patch-8
shiroow-patch-7
shiroow-patch-6
shiroow-patch-5
shiroow-patch-4
shiroow-patch-3
shiroow-patch-2
shiroow-patch-1
check_sudo_permissions
feature/euphoria
add_next_octet_to_ip_settings
bugfix/mobile-controllers-init
euphoria
bugfix/android-crush
feature/macox-network-extension
bugfix/pre-release-hotfixes
bugfix/ipsec-pfs
chore/ios-site-links
checking_sudo_permissions
feature/android-tv
improve_navigation_cpp
bugfix/linux-firewall-install
fixbug/wireguard-handshake-time
ReadmeRu_full
feature/xray-user-management
feature/subscription-end-date
chore/clang-format
feature/ru-in-readme
chore/increased-api-timeout
chore/deploy-workflow
bugfix/services-list-scroll
wheel_group_suppor
chore/bump-xcode-version
fixbug/mac-network-extension
feature/android-gpb
feature/page-home-drawer-country-selection
checking-sudo-users
bugfix/service-info-from-response
fixbug/build-macos-ne-2
android-qt-6.7.3
fixbug/build-macos-ne
bugfix/wg-windows-log-folder
feature/psk-key-api-request
bugfix/user-management-qml-warnings
fix/macos-network-extension
fixbug/macos-NE-build
bugfix/fixed-isDevEnv-initialization
bugfix/revert-ios-ovpn
feature/tun2socksSrv
fix/disable_singleapp
feature/awg-wg-name-resolving
feature/disable-dhcp
bugfix/allowed-ips-old-configs
feature/goodbyedpi
feature/add-exception-log
refactoring/remove-ipv6-from-default-routes
refactoring/singleapplication-submodule
macos-dirty-build
test/gateway
Update-amneziavpn_fa_IR.ts
bugfix/ipsec-win
fix/xray-custom-port
improve-tab-navigation
test-win-11
feature/android-tv-remote-control-support
KsZnak-patch-1
feature/awg-wg-qr
bugfix/fix-loopback-splittunel
fix/setup_host_firewall
feature/android-xray
feature/openvpn-pass
feature/connection-string
fix/clickable-errors
bugfix/api_1100_fix
feature/graphview
testsvg
feature/update-win-awg
feature/open-as-amnezia
feature/update-mozilla-upstream
bugfix/qr-code-cutting
feature/native-wg-psk
test/awg-centos
bugfix/hide_error
feature/add-uninstaller-checkbox
bugfix/cancel-button-on-install-page
bugfix/anchors-page-home-warning
awg-udptlspipe
button-focus-fix
revert-677-fix/logger
bugfix/Revert_PR_596
bugfix/allowed-ips-api-configs
bugfix/on-escape-pressed
feature/auto-scroll-for-server-selection-list
fix/ui-fixes
translations/update_fa_IR.ts
feature/new-awg-docker-container
bugfix/awg_ipv6_fix
feature/tab-navigation
fix/username-no-autocapitalization
sure
refactoring/servers-model-cleanup
feature/wg-mtu-setup-ios
3rd_adaptation_to_diff_OS
sudo_not_found
test/docker-ce
bugfix/double_clear_server_from_amnezia
fix/android
client/3rd-prebuilt
revert-559-KsZnak-translation-ru-ex
KsZnak-translation-ru-ex
KsZnak-br1
KsZnak-text-change
feature/api-awg
feature/error-code-output
feature/win_x32_builds
text/debug-output
feature/ovpn3-desktop-cli
bugfix/secureqsettings-deadlock
refactoring/change-settings-when-connected
files_check
ArchLinux-support
second_adaptation_to_diff_os
sudo
refactoring/android-build
adaptation_to_different_os
feature/online_installer_for_v4
update_to_r2
bugfix/return-after-installation
feature/custom_drawer_component
bugfix/split-tunneling
bugfix/existing-awg-container
revert-370-feature/custom_drawer_component
bugfix/adapted_awg_questiondrawer
bugfix/updated_drawer_height_pageserverdata
bugfix/translated_new_source_strings_to_chinese
feature/split-tunneling-config
feature/accessibility-support
branch_connectivity_change_fix
feature/ikev2_android
android_ss_transport
bugfix/macos_fixes
feature/nextcloud-support
feature/macos_network_extension
android_pt_transport_source
feature/ios-openvpn3-pluggable-transport-Cloak
bugfix/cloak_for_desktops_fix
arm-build-macos
fix-macos-build-brew
bugfix/ios-build-openvpnadapter-from-source
feature/download-native-wireguard-config-on-connect
feature/v2ray-container
bugfix/dpkg-busy-checking-stuck
feature/online-installer
dev-killswitch
dev-netadapters
5.1.0.6
5.0.4.2
5.0.4.1
5.0.4.0
5.0.3.0
5.0.2.1
5.0.2.0
5.0.1.5
5.0.0.5
5.0.0.2
4.8.21.0
4.8.19.0
4.8.18.0
4.8.17.0
4.8.16.0
4.8.15.4
4.8.15.0
4.8.14.5
4.8.14.1
4.8.12.9
4.8.12.8
4.8.12.7
4.8.12.6
4.8.11.4
4.8.11.3
4.8.11.2
4.8.11.1
4.8.11.0
4.8.10.0
4.8.9.2
4.8.9.1
4.8.9.0
4.8.8.3
4.8.8.2
4.8.8.1
4.8.7.2
4.8.7.1
4.8.7.0
4.8.6.0
4.8.5.0
4.8.4.5
4.8.4.4
4.8.4.3
4.8.4.2
4.8.4.1
4.8.4.0
4.8.3.2
4.8.3.1
4.8.2.3
4.8.1.9
4.8.1.0
4.8.0.5
4.7.0.0
4.6.0.3
4.6.0.1
4.5.3.0
4.5.0.0
4.4.0.0
4.3.0.0
4.2.1.0
4.2.0.1
4.1.2.0_cloak_pt_experimental
4.1.0.1
4.0.8
3.1.0
3.0.8
3.0.7
3.0.5
2.1.2
2.1.0
2.0.10
2.0.9
2.0.8
2.0.7
2.0.6
2.0.5
2.0.1
2.0
1.9.1
1.9
1.8
1.7
1.6
1.5
1.4
1.3
1.2
1.1
1.0
No labels
pull-request
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
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#3198
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/amnezia-vpn/amnezia-client/pull/3327
Author: @justSunny12
Created: 10/26/2026
Status: 🔄 Open
Base:
dev← Head:feat/reresolve-endpoint-on-stale-handshake📝 Commits (1)
1b3ae0afeat: follow server IP changes behind the host name without a manual reconnect📊 Changes
25 files changed (+741 additions, -6 deletions)
View changed files
📝
.github/workflows/deploy.yml(+3 -0)📝
client/android/protocolApi/src/main/kotlin/Protocol.kt(+9 -1)📝
client/android/src/org/amnezia/vpn/AmneziaVpnService.kt(+1 -1)📝
client/android/utils/src/main/kotlin/net/NetworkUtils.kt(+10 -0)➕
client/android/wireguard/src/main/kotlin/org/amnezia/vpn/protocol/wireguard/EndpointWatchdog.kt(+71 -0)📝
client/android/wireguard/src/main/kotlin/org/amnezia/vpn/protocol/wireguard/Wireguard.kt(+94 -1)📝
client/android/wireguard/src/main/kotlin/org/amnezia/vpn/protocol/wireguard/WireguardConfig.kt(+2 -1)📝
client/cmake/sources.cmake(+2 -0)📝
client/core/protocols/vpnProtocol.h(+3 -0)📝
client/core/protocols/wireGuardProtocol.cpp(+56 -2)📝
client/core/protocols/wireGuardProtocol.h(+16 -0)➕
client/core/utils/endpointWatchdog.cpp(+53 -0)➕
client/core/utils/endpointWatchdog.h(+56 -0)📝
client/daemon/daemon.cpp(+3 -0)📝
client/ios/networkextension/CMakeLists.txt(+1 -0)📝
client/macos/networkextension/CMakeLists.txt(+1 -0)📝
client/mozilla/controllerimpl.h(+5 -0)📝
client/mozilla/localsocketcontroller.cpp(+7 -0)➕
client/platforms/ios/EndpointWatchdog.swift(+75 -0)📝
client/platforms/ios/PacketTunnelProvider+WireGuard.swift(+100 -0)...and 5 more files
📄 Description
Problem
A WireGuard/AWG config can name the server by host name (
Endpoint = vpn.example.com:443). The client resolves that name once per connection and keeps using the resulting IP. When the address behind the name changes, every connected device keeps sending to the old IP and stays offline until the user toggles the tunnel by hand.This happens in practice when:
In all these cases the server side cannot fix it, and the user often doesn't understand why "the VPN is connected but nothing works".
Why nothing recovers today (checked against
dev@3121775andamneziawg-apple@ bdaf0b3):WireguardProtocol::startMzImpl()overwriteshostNameinm_rawConfigwith the IPnetworkChanged/wakeupcallstart()again, but the config already holds the IP, so they reuse the old addressparseInetAddress()inWireguard.configWireguard()reconnectVpn()reuses the savedWireguardConfigwith the resolved addressWireGuardAdapter.start()→resolvePeers()didReceivePathUpdate()→endpointUapiConfiguration()re-resolves the already resolved IP (resolvedEndpoints) for NAT64 synthesis, not the host namewgBumpSockets()The engine cannot recover on its own either:
amneziawg-gonever resolves names. AfterMaxHandshakeAttemptsit gives up until the next outgoing packet.DisableSomeRoamingForBrokenMobileSemantics(), so a packet from a new source address doesn't move the endpoint. Even without that, stateful NAT drops packets from an address the device didn't contact.Solution
Detect a tunnel that is up on the device but no longer reaches its server, then resolve the configured host name again. The detection rule is the one from wireguard-tools'
contrib/reresolve-dns: the latest handshake is older than a rekey cycle while the device keeps sending to the peer.A live session with traffic or PersistentKeepalive renews its handshake every 120 s (
REKEY_AFTER_TIME); a failed renewal is retried for 90 s more (REKEY_ATTEMPT_TIME). So "no handshake for 180 s and tx grew during that window" means the server is unreachable.An idle tunnel without keepalive never handshakes and sends nothing, so it is never treated as stale. Before the first handshake, the age is counted from the tunnel start.
The same small state machine is implemented on every platform. It is pure logic with no I/O, and the C++ version is unit-tested:
client/core/utils/endpointWatchdog.{h,cpp}— desktop, withclient/tests/testEndpointWatchdog.cppclient/android/wireguard/.../EndpointWatchdog.ktclient/platforms/ios/EndpointWatchdog.swiftIt also rate-limits refreshes: the delay doubles after each attempt and resets on the next successful handshake.
Desktop (Windows, Linux, macOS with daemon)
WireguardProtocolkeeps the host names exactly as configured and resolves them on everystart(). This alone makes the existing reconnects on network change and wakeup follow DNS changes.WireguardProtocolpollscheckStatus()every 20 s.statusreply gets an optionallastHandshakefield (ms since epoch, fromPeerStatus::m_handshake).LocalSocketControlleremits it as the newControllerImpl::peerStatusUpdated()signal.VpnProtocol::reconnectRequested().VpnConnection::onProtocolReconnectRequested()restarts the protocol exactly likereconnectToVpn(), but without requiring theConnectedstate: after a reconnect to an unreachable server the UI state may already be different.Android
Wireguardremembers the configured host name (nullfor IP literals; newisNumericAddress()inutils, which never queries DNS).awgGetConfig()every 20 s. When the tunnel is stale, it resolves the name on an underlying network (Network.getAllByName()on a non-VPN network withINTERNET), because DNS through the dead tunnel doesn't work.WireguardConfig.endpointbecomes avar. The protocol asks the service through a new optionalrequestReconnectparameter ofProtocol.initialize()(default{}, so other protocols are untouched), andAmneziaVpnServicepasses its existingreconnect().iOS and macOS (Network Extension)
PacketTunnelProviderkeeps the startedTunnelConfigurationand pollsgetRuntimeConfiguration()every 20 s on its own queue.DNSResolver.resolveSync()and compares the result with the address the name had at tunnel start. Comparing with the engine's runtime endpoint would be wrong on NAT64 networks, where it holds a synthesized IPv6.WireGuardAdapter.update(tunnelConfiguration:), which resolves peers again and applies the configuration. No change to theamneziawg-applesubmodule is needed.startWireguard()and on a configuration switch from the app, and stops instopWireguard().Behaviour
Only WireGuard and AWG are affected. OpenVPN, Xray and IKEv2 code paths are untouched.
Backward compatibility
hostNameis used.statusreply.Protocol.initialize()gets a new parameter with a default value.awgGetConfig, UAPIlast_handshake_time_*/tx_bytes,WireGuardAdapter.update,DNSResolver.resolveSync).Testing
Everything below was run on this branch (
dev@3121775+ this change). All scripts and full logs are attached in the collapsible sections, so every step can be reproduced.Environment
.github/workflows/deploy.ymlandroid-35;google_apis;arm64-v8ar9recipes/awg-android). Linux desktop:amneziawg-gobuilt by the project. Lab servers: AmneziaWG kernel module and amneziawg-tools 3.1.20260812. Android test servers: amneziawg-go @ 457d920a1a7d (userspace, netstack)amneziawg-apple@ bdaf0b3 (unchanged)Builds
All builds use
deploy/build.shas in CI. For Apple targets the generated Xcode project is built with signing disabled, because the team's provisioning profiles are not available outside CI.AMNEZIA_BUILD_TESTS=ON deploy/build.sh --generator NinjaCMAKE_PREFIX_PATH=<qt>/gcc_arm64deploy/build.sh -t macos-ne, thenxcodebuild -target AmneziaVPNNetworkExtension CODE_SIGNING_ALLOWED=NOdeploy/build.sh -t ios, thenxcodebuild -target networkextension -sdk iphoneos CODE_SIGNING_ALLOWED=NOdeploy/build.sh -t android --abi arm64-v8a --sign(throwaway keystore):compileOssReleaseKotlinand:compilePlayReleaseKotlin, signed APK¹ The macOS NE app target fails on unchanged
platforms/ios/LogController.swift(std.string(...): no exact matches) with the Xcode 27 SDK. That is unrelated to this change; CI uses Xcode 26.3.Unit tests
cteston the full test set. The newEndpointWatchdogTestis registered inclient/tests/CMakeLists.txtand added to the three CI test matrices.ctest, Linux arm64
EndpointWatchdogTest, macOS (per test function)
Live scenarios
Every scenario uses real AmneziaWG timers and has two servers with the same keys and AWG parameters:
vpn.testis moved to.The client config uses
Endpoint = vpn.test:51820and PersistentKeepalive 25, except where stated.endpointWatchdog.cppitself, fed withawg show dumpevery 20 svpn.test→ Bvpn.test→ B; user traffic starts at 312 svpn.teststays on A0.0.0.0/0, DNS inside the tunnel (so DNS through the dead tunnel cannot work)vpn.test→ Bit moved to …: reconnecting, handshake with B, 160 s offlinevpn.teststays on AAmneziaVPN-service(root) +VpnConnectionConnectionUiController::toggleConnection()vpn.test→ Bvpn.teststays on ANot run live: iOS and macOS NE. A Network Extension doesn't run in the simulator and needs provisioning to run on a device. Both extensions compile and link with the change.
The Swift watchdog passes the same scenarios as the C++ one, and the Apple code path uses only WireGuardKit's own
DNSResolver.resolveSync()and the publicWireGuardAdapter.update().Scenarios 1–3: log
Scenario 4 (Android, moved): log
Scenario 5 (Android, dead): log
Scenario 6 (desktop, moved): log
Scenario 7 (desktop, dead): log
Test harness (not part of the change)
e2e.sh — scenarios 1–3 (Linux, root, network namespaces)
driver.cpp — feeds `awg show dump` samples into EndpointWatchdog
android-e2e.sh — scenarios 4–5 (macOS host, Android emulator)
awgsrv/main.go — rootless AmneziaWG test server (amneziawg-go + netstack), bound to one IP
dns.py — test DNS for the emulator with a switchable record
desktop-e2e.sh — scenarios 6–7 (Linux, real service and client)
desktopE2e.cpp — client harness on top of the tests' TestCoreController
Notes on the harness:
ConnectionUiControllerfromConnectionController::connectionStateChanged. ItsConnectedbranch callsamnApp->networkManager(), which does not exist outside the full application. The connection path itself (ConnectionController→VpnConnection→WireguardProtocol→ daemon) is untouched.AwgServicethroughadb(root) with the same JSON the app sends, and grants VPN consent withappops.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
bad_record_mac), YouTube/Discord unusable. Setting MTU 1280/1200 fixes it #3239