aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorcopilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>2025-12-07 00:21:06 +0000
committercopilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>2025-12-07 00:21:06 +0000
commit0a66469fd81446b5d54becd049f8da90898cc85c (patch)
treeaf8155e0877f85a81de8ab7b47fdae99ab0639fd /src
parent4e02b95eeac1cdd3d49f0ca0177f9d59a76e9ce4 (diff)
downloadslskd-0a66469fd81446b5d54becd049f8da90898cc85c.tar.gz
Fix Mutex logic and protect disposal from throwing exceptions
Co-authored-by: jpdillingham <17145758+jpdillingham@users.noreply.github.com>
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Program.cs15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index bafac8b1..85cc4a3a 100644
--- a/src/slskd/Program.cs
+++ b/src/slskd/Program.cs
@@ -337,9 +337,10 @@ namespace slskd
// only one long-running instance.
try
{
- Mutex = new Mutex(initiallyOwned: true, Compute.Sha256Hash(AppName));
+ bool createdNew;
+ Mutex = new Mutex(initiallyOwned: true, Compute.Sha256Hash(AppName), out createdNew);
- if (!Mutex.WaitOne(millisecondsTimeout: 0, exitContext: false))
+ if (!createdNew)
{
Log.Fatal($"An instance of {AppName} is already running");
return;
@@ -564,7 +565,15 @@ namespace slskd
}
finally
{
- Mutex?.Dispose();
+ try
+ {
+ Mutex?.Dispose();
+ }
+ catch
+ {
+ // Ignore disposal errors to prevent masking other exceptions
+ }
+
Serilog.Log.CloseAndFlush();
}
}