From c5334bc7007a8ca9fd538754875f4bb197b01b7f Mon Sep 17 00:00:00 2001 From: socrabs151 Date: Wed, 18 Nov 2026 10:01:30 +0300 Subject: [PATCH] fix: keep the Linux single-instance mutex alive (#10629) Store the named mutex in a static field. Discarding it lets the runtime release/finalize it, so a second launch no longer sees the first instance and a new process starts. --- v2rayN/v2rayN.Desktop/Program.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/v2rayN/v2rayN.Desktop/Program.cs b/v2rayN/v2rayN.Desktop/Program.cs index 62d8d721..784ae6ce 100644 --- a/v2rayN/v2rayN.Desktop/Program.cs +++ b/v2rayN/v2rayN.Desktop/Program.cs @@ -6,6 +6,7 @@ namespace v2rayN.Desktop; internal class Program { public static EventWaitHandle ProgramStarted; + private static Mutex? _instanceMutex; // Initialization code. Don't use any Avalonia, third-party APIs or any // SynchronizationContext-reliant code before AppMain is called: things aren't initialized @@ -38,7 +39,9 @@ internal class Program } else { - _ = new Mutex(true, "v2rayN", out var bOnlyOneInstance); + // Keep the named mutex alive for the process lifetime. Discarding the handle lets + // the runtime finalize it, so the next launch sees no running instance. + _instanceMutex = new Mutex(true, "v2rayN", out var bOnlyOneInstance); if (!bOnlyOneInstance) { return false;