* [PATCH] api: use mutex when removing instance on close adapter
@ 2026-02-02 14:36 Jean-Alexandre CHRONE
2026-03-06 10:05 ` Jean-Alexandre CHRONE
0 siblings, 1 reply; 2+ messages in thread
From: Jean-Alexandre CHRONE @ 2026-02-02 14:36 UTC (permalink / raw)
To: wireguard@lists.zx2c4.com; +Cc: Jean-Alexandre CHRONE
From 298267d3ead7110880a5dc0f5d0e8822600d30c0 Mon Sep 17 00:00:00 2001
From: "jean-alexandre.chrone" <jean-alexandre.chrone@stormshield.eu>
Date: Mon, 2 Feb 2026 15:24:12 +0100
Subject: [PATCH] api: use mutex when removing instance on close adapter
on successive create and close there might be some error logged
---
api/adapter.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/api/adapter.c b/api/adapter.c
index 0dd8c42..042645c 100644
--- a/api/adapter.c
+++ b/api/adapter.c
@@ -158,7 +158,8 @@ VOID AdapterCleanupOrphanedDevices(VOID)
continue;
}
ULONG Status, Code;
- if (CM_Get_DevNode_Status(&Status, &Code, DevInfoData.DevInst, 0) == CR_SUCCESS && !(Status & DN_HAS_PROBLEM))
+ CONFIGRET Ret = CM_Get_DevNode_Status(&Status, &Code, DevInfoData.DevInst, 0);
+ if ((Ret == CR_SUCCESS && !(Status & DN_HAS_PROBLEM)) || Ret == CR_NO_SUCH_DEVNODE)
continue;
DEVPROPTYPE PropType;
@@ -195,8 +196,16 @@ WintunCloseAdapter(WINTUN_ADAPTER *Adapter)
SwDeviceClose(Adapter->SwDevice);
if (Adapter->DevInfo)
{
+ HANDLE DeviceInstallationMutex = NamespaceTakeDeviceInstallationMutex();
+ if (DeviceInstallationMutex == NULL)
+ LOG_LAST_ERROR(L"Failed to take device installation mutex");
+
if (!AdapterRemoveInstance(Adapter->DevInfo, &Adapter->DevInfoData))
LOG_LAST_ERROR(L"Failed to remove adapter when closing");
+
+ if (DeviceInstallationMutex != NULL)
+ NamespaceReleaseMutex(DeviceInstallationMutex);
+
SetupDiDestroyDeviceInfoList(Adapter->DevInfo);
}
Free(Adapter);
--
2.52.0.windows.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* RE: [PATCH] api: use mutex when removing instance on close adapter
2026-02-02 14:36 [PATCH] api: use mutex when removing instance on close adapter Jean-Alexandre CHRONE
@ 2026-03-06 10:05 ` Jean-Alexandre CHRONE
0 siblings, 0 replies; 2+ messages in thread
From: Jean-Alexandre CHRONE @ 2026-03-06 10:05 UTC (permalink / raw)
To: wireguard@lists.zx2c4.com
Hello,
Did anyone have the same issue as mentioned in the earlier message?
We encountered it any time we had to reset an adapter multiple times in a short lapse of time.
Best Regards,
Jean-Alexandre
-----Original message-----
From 298267d3ead7110880a5dc0f5d0e8822600d30c0 Mon Sep 17 00:00:00 2001
From: "jean-alexandre.chrone" <jean-alexandre.chrone@stormshield.eu>
Date: Mon, 2 Feb 2026 15:24:12 +0100
Subject: [PATCH] api: use mutex when removing instance on close adapter
on successive create and close there might be some error logged
---
api/adapter.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/api/adapter.c b/api/adapter.c index 0dd8c42..042645c 100644
--- a/api/adapter.c
+++ b/api/adapter.c
@@ -158,7 +158,8 @@ VOID AdapterCleanupOrphanedDevices(VOID)
continue;
}
ULONG Status, Code;
- if (CM_Get_DevNode_Status(&Status, &Code, DevInfoData.DevInst, 0) == CR_SUCCESS && !(Status & DN_HAS_PROBLEM))
+ CONFIGRET Ret = CM_Get_DevNode_Status(&Status, &Code, DevInfoData.DevInst, 0);
+ if ((Ret == CR_SUCCESS && !(Status & DN_HAS_PROBLEM)) || Ret ==
+ CR_NO_SUCH_DEVNODE)
continue;
DEVPROPTYPE PropType;
@@ -195,8 +196,16 @@ WintunCloseAdapter(WINTUN_ADAPTER *Adapter)
SwDeviceClose(Adapter->SwDevice);
if (Adapter->DevInfo)
{
+ HANDLE DeviceInstallationMutex = NamespaceTakeDeviceInstallationMutex();
+ if (DeviceInstallationMutex == NULL)
+ LOG_LAST_ERROR(L"Failed to take device installation
+ mutex");
+
if (!AdapterRemoveInstance(Adapter->DevInfo, &Adapter->DevInfoData))
LOG_LAST_ERROR(L"Failed to remove adapter when closing");
+
+ if (DeviceInstallationMutex != NULL)
+ NamespaceReleaseMutex(DeviceInstallationMutex);
+
SetupDiDestroyDeviceInfoList(Adapter->DevInfo);
}
Free(Adapter);
--
2.52.0.windows.1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-06 10:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-02 14:36 [PATCH] api: use mutex when removing instance on close adapter Jean-Alexandre CHRONE
2026-03-06 10:05 ` Jean-Alexandre CHRONE
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox