From e3b294bf69364ddfa4b97dfd605206a85f669802 Mon Sep 17 00:00:00 2001 From: andbul0103 Date: Sun, 14 Jun 2026 19:54:15 +0400 Subject: [PATCH] Fix tunnel killed during connect by VPN-interface watchdog The stats updater treated "WireGuard interface not up within 6s of the Go client process start" as a lost/replaced VPN interface and emergency- stopped the tunnel. But the interface only comes up after the client finishes captcha -> VK creds -> WRAP -> TURN/DTLS -> WireGuard config, which takes far longer than 6s (especially with manual captcha mode), so the tunnel was killed ~7s into every connect before it could establish. Watch for an interface that was actually up and then disappeared instead of a fixed startup window: only emergency-stop once the tunnel has been observed UP at least once. The connect phase of any duration is no longer policed, while a real tun loss/replacement is still caught. Co-Authored-By: Claude Opus 4.8 (1M context) --- app/src/main/java/com/wdtt/client/TunnelService.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/wdtt/client/TunnelService.kt b/app/src/main/java/com/wdtt/client/TunnelService.kt index 5dd93ef..8b06bd5 100644 --- a/app/src/main/java/com/wdtt/client/TunnelService.kt +++ b/app/src/main/java/com/wdtt/client/TunnelService.kt @@ -280,6 +280,12 @@ class TunnelService : Service() { private fun startStatsUpdater() { updateJob?.cancel() updateJob = TunnelManager.scope.launch(Dispatchers.Main) { + // Сторож следит за ПРОПАЖОЙ уже поднятого VPN-интерфейса, а не за его + // отсутствием во время подключения. Фаза установки туннеля (капча → VK-креды → + // WRAP → TURN/DTLS → выдача WireGuard-конфига) может занимать значительно больше + // времени, чем любое фиксированное окно, особенно при ручном обходе капчи, поэтому + // аварийно глушим туннель только если интерфейс был поднят и затем пропал/заменён. + var wasEverUp = false delay(1000) while (isActive) { if (!TunnelManager.running.value && !isTunnelPaused) { @@ -289,8 +295,9 @@ class TunnelService : Service() { } if (TunnelManager.running.value && !isTunnelPaused) { val helper = WireGuardHelper(applicationContext) - val startupWindow = System.currentTimeMillis() - TunnelManager.processStartedAtMs < 6000 - if (!startupWindow && !helper.isTunnelUp()) { + if (helper.isTunnelUp()) { + wasEverUp = true + } else if (wasEverUp) { Log.w("TunnelService", "Обнаружена пропажа или замена VPN-интерфейса! Экстренное выключение туннеля.") stopTunnel() break