subhra74/xdm · info · InstanceAlreadyRunningException
XDM instance already running, Mutex exists…
Error message
XDM instance already running, Mutex exists 'Global\XDM_Active_Instance'
What it means
XDM enforces a single active instance across the machine using a named system-wide mutex 'Global\XDM_Active_Instance'. NativeMessagingHostHandler.EnsureSingleInstance opens this mutex; if it exists, another XDM instance is already running and it throws InstanceAlreadyRunningException. The exception is immediately caught and logged at Debug level, so it functions as an instance-detection signal rather than a fatal error.
Solutions
- Close the existing XDM instance (check system tray and Task Manager for XDM processes) before starting the native messaging host or a second copy
- If no visible instance exists, kill orphaned XDM processes in Task Manager; the Global mutex is released when the owning process exits
- If you must run the host independently, ensure your code catches InstanceAlreadyRunningException from EnsureSingleInstance and treats it as 'instance detected', not a failure
- Reboot as a last resort if a zombie process holds the mutex and cannot be identified
Example fix
// before
EnsureSingleInstance(); // throws if XDM already running
// after
try
{
EnsureSingleInstance();
}
catch (InstanceAlreadyRunningException)
{
Log.Info("XDM main instance already running; exiting host gracefully");
return;
} Defensive patterns
Strategy: try-catch
Validate before calling
// Probe for an existing instance before performing work
Mutex existing;
var probe = Mutex.TryOpenExisting(@"Global\XDM_Active_Instance", out existing);
if (probe) { /* another instance is running */ } Try / catch
try
{
NativeMessagingHostHandler.EnsureSingleInstance();
}
catch (InstanceAlreadyRunningException ex)
{
Log.Info("XDM already running: {0}", ex.Message);
return; // exit gracefully
} Prevention
- Always call EnsureSingleInstance inside try/catch and treat InstanceAlreadyRunningException as a normal detection signal
- Check for running XDM processes (tray icon / Task Manager) before launching the native messaging host
- Never manually delete or spoof the Global mutex; rely on process exit to release it
When it happens
Trigger: Calling NativeMessagingHostHandler.EnsureSingleInstance (e.g. from the native messaging host startup path) while another XDM process already holds the 'Global\XDM_Active_Instance' mutex.
Common situations: Launching the browser native messaging host while the main XDM app is running; a crashed XDM process that failed to release the mutex (rare, mutexes die with the process); running XDM under multiple Windows sessions where the Global mutex is shared.
Related errors
AI-assisted analysis of subhra74/xdm@1ca5a25aae (2026-09-13).
Data as JSON: /api/errors/7aad8ed34593e1d0.
Report an issue: GitHub.
Appendix: source
Thrown at app/XDM/XDM.Core/BrowserMonitoring/NativeMessagingHostHandler.cs:31
#endif
using TraceLog;
namespace XDM.Core.BrowserMonitoring
{
public class NativeMessagingHostHandler : IDisposable
{
private int MaxPipeInstance = 254;
private static readonly string PipeName = "XDM_Ipc_Browser_Monitoring_Pipe";
private List<NativeMessagingHostChannel> connectedChannels = new();
private static Mutex globalMutex;
private Thread listenerThread;
public static void EnsureSingleInstance()
{
try
{
using var mutex = Mutex.OpenExisting(@"Global\XDM_Active_Instance");
throw new InstanceAlreadyRunningException(@"XDM instance already running, Mutex exists 'Global\XDM_Active_Instance'");
}
catch (Exception ex)
{
Log.Debug(ex, "Exception in NativeMessagingHostHandler ctor");
if (ex is InstanceAlreadyRunningException)
{
var args = Environment.GetCommandLineArgs().Skip(1);
if (args.Count() > 0)
{
Log.Debug(ex, "Sending args to running instance");
SendArgsToRunningInstance(args);
Environment.Exit(0);
}
throw;
}
}
globalMutex = new Mutex(true, @"Global\XDM_Active_Instance");
}
View on GitHub (pinned to 1ca5a25aae)