From d381d429e46d3e235828b5d099c1cb134f7e4f20 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Wed, 5 Aug 2026 17:03:23 +0800 Subject: [PATCH] Wait briefly after sudo process kills https://github.com/2dust/v2rayN/issues/9863 Add a short 1-second delay after terminating core processes on Linux, macOS, and in CoreAdminManager so ports and process resources have time to settle before the next step runs. --- v2rayN/ServiceLib/Manager/CoreAdminManager.cs | 2 ++ v2rayN/ServiceLib/Sample/kill_as_sudo_linux_sh | 5 +++++ v2rayN/ServiceLib/Sample/kill_as_sudo_osx_sh | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/v2rayN/ServiceLib/Manager/CoreAdminManager.cs b/v2rayN/ServiceLib/Manager/CoreAdminManager.cs index db6d9021..79680c2e 100644 --- a/v2rayN/ServiceLib/Manager/CoreAdminManager.cs +++ b/v2rayN/ServiceLib/Manager/CoreAdminManager.cs @@ -91,6 +91,8 @@ public class CoreAdminManager .ExecuteBufferedAsync(); await UpdateFunc(false, result.StandardOutput.ToString()); + + await Task.Delay(1000); // Wait for a second to ensure the process is killed } catch (Exception ex) { diff --git a/v2rayN/ServiceLib/Sample/kill_as_sudo_linux_sh b/v2rayN/ServiceLib/Sample/kill_as_sudo_linux_sh index 21e17408..392c5c20 100644 --- a/v2rayN/ServiceLib/Sample/kill_as_sudo_linux_sh +++ b/v2rayN/ServiceLib/Sample/kill_as_sudo_linux_sh @@ -66,6 +66,11 @@ kill_children "$PID" echo "Terminating main process: $PID" kill -9 "$PID" 2>/dev/null || true +# Wait a little for process/port resources to be fully released +FINAL_WAIT_SECONDS=1 +echo "Waiting ${FINAL_WAIT_SECONDS}s for resources to settle..." +sleep "$FINAL_WAIT_SECONDS" + echo "============================================" echo "Process $PID and all its children have been terminated" echo "============================================" diff --git a/v2rayN/ServiceLib/Sample/kill_as_sudo_osx_sh b/v2rayN/ServiceLib/Sample/kill_as_sudo_osx_sh index 61160fa2..f0511183 100644 --- a/v2rayN/ServiceLib/Sample/kill_as_sudo_osx_sh +++ b/v2rayN/ServiceLib/Sample/kill_as_sudo_osx_sh @@ -63,6 +63,11 @@ kill_descendants "$PID" echo "Terminating main process: $PID" kill -9 "$PID" 2>/dev/null || true +# Wait a little for process/port resources to be fully released +FINAL_WAIT_SECONDS=1 +echo "Waiting ${FINAL_WAIT_SECONDS}s for resources to settle..." +sleep "$FINAL_WAIT_SECONDS" + echo "============================================" echo "Process $PID and all its descendants have been terminated" echo "============================================"