api: retry on ERROR_TRANSACTION_NOT_ACTIVE when disabling dead GW detect
There seems to be a race in the TCP/IP adapter registry key. Sometimes, the adapter TCP/IP key is created, but setting the value EnableDeadGWDetect fails with ERROR_TRANSACTION_NOT_ACTIVE. Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
c18dd0a216
commit
f7c2ea4ded
@ -1497,34 +1497,45 @@ static _Return_type_success_(return != NULL) WINTUN_ADAPTER *CreateAdapter(
|
|||||||
}
|
}
|
||||||
Free(DummyStr);
|
Free(DummyStr);
|
||||||
|
|
||||||
HKEY TcpipInterfaceRegKey;
|
|
||||||
WCHAR TcpipInterfaceRegPath[MAX_REG_PATH];
|
WCHAR TcpipInterfaceRegPath[MAX_REG_PATH];
|
||||||
if (!GetTcpipInterfaceRegPath(Adapter, TcpipInterfaceRegPath))
|
if (!GetTcpipInterfaceRegPath(Adapter, TcpipInterfaceRegPath))
|
||||||
{
|
{
|
||||||
LastError = LOG(WINTUN_LOG_ERR, L"Failed to determine interface-specific TCP/IP network registry key path");
|
LastError = LOG(WINTUN_LOG_ERR, L"Failed to determine interface-specific TCP/IP network registry key path");
|
||||||
goto cleanupTcpipAdapterRegKey;
|
goto cleanupTcpipAdapterRegKey;
|
||||||
}
|
}
|
||||||
TcpipInterfaceRegKey = RegistryOpenKeyWait(
|
for (int Tries = 0; Tries < 300; ++Tries)
|
||||||
HKEY_LOCAL_MACHINE, TcpipInterfaceRegPath, KEY_QUERY_VALUE | KEY_SET_VALUE, WAIT_FOR_REGISTRY_TIMEOUT);
|
|
||||||
if (!TcpipInterfaceRegKey)
|
|
||||||
{
|
{
|
||||||
LastError = LOG(WINTUN_LOG_ERR, L"Failed to open interface-specific TCP/IP network registry key");
|
HKEY TcpipInterfaceRegKey = RegistryOpenKeyWait(
|
||||||
goto cleanupTcpipAdapterRegKey;
|
HKEY_LOCAL_MACHINE, TcpipInterfaceRegPath, KEY_QUERY_VALUE | KEY_SET_VALUE, WAIT_FOR_REGISTRY_TIMEOUT);
|
||||||
}
|
if (!TcpipInterfaceRegKey)
|
||||||
|
{
|
||||||
|
LastError = LOG(WINTUN_LOG_ERR, L"Failed to open interface-specific TCP/IP network registry key");
|
||||||
|
goto cleanupTcpipAdapterRegKey;
|
||||||
|
}
|
||||||
|
|
||||||
static const DWORD EnableDeadGWDetect = 0;
|
static const DWORD EnableDeadGWDetect = 0;
|
||||||
LastError = RegSetKeyValueW(
|
LastError = RegSetKeyValueW(
|
||||||
TcpipInterfaceRegKey, NULL, L"EnableDeadGWDetect", REG_DWORD, &EnableDeadGWDetect, sizeof(EnableDeadGWDetect));
|
TcpipInterfaceRegKey,
|
||||||
if (LastError != ERROR_SUCCESS)
|
NULL,
|
||||||
{
|
L"EnableDeadGWDetect",
|
||||||
LOG_ERROR(L"Failed to set EnableDeadGWDetect", LastError);
|
REG_DWORD,
|
||||||
goto cleanupTcpipInterfaceRegKey;
|
&EnableDeadGWDetect,
|
||||||
|
sizeof(EnableDeadGWDetect));
|
||||||
|
RegCloseKey(TcpipInterfaceRegKey);
|
||||||
|
if (LastError == ERROR_SUCCESS)
|
||||||
|
break;
|
||||||
|
if (LastError != ERROR_TRANSACTION_NOT_ACTIVE || Tries == 299)
|
||||||
|
{
|
||||||
|
LOG_ERROR(L"Failed to set EnableDeadGWDetect", LastError);
|
||||||
|
goto cleanupTcpipAdapterRegKey;
|
||||||
|
}
|
||||||
|
Sleep(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!WintunSetAdapterName(Adapter, Name))
|
if (!WintunSetAdapterName(Adapter, Name))
|
||||||
{
|
{
|
||||||
LastError = LOG(WINTUN_LOG_ERR, L"Failed to set adapter name");
|
LastError = LOG(WINTUN_LOG_ERR, L"Failed to set adapter name");
|
||||||
goto cleanupTcpipInterfaceRegKey;
|
goto cleanupTcpipAdapterRegKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
DEVPROPTYPE PropertyType;
|
DEVPROPTYPE PropertyType;
|
||||||
@ -1547,7 +1558,7 @@ static _Return_type_success_(return != NULL) WINTUN_ADAPTER *CreateAdapter(
|
|||||||
if (ProblemStatus != STATUS_PNP_DEVICE_CONFIGURATION_PENDING || Tries == 999)
|
if (ProblemStatus != STATUS_PNP_DEVICE_CONFIGURATION_PENDING || Tries == 999)
|
||||||
{
|
{
|
||||||
LOG_ERROR(L"Failed to setup adapter", LastError);
|
LOG_ERROR(L"Failed to setup adapter", LastError);
|
||||||
goto cleanupTcpipInterfaceRegKey;
|
goto cleanupTcpipAdapterRegKey;
|
||||||
}
|
}
|
||||||
Sleep(10);
|
Sleep(10);
|
||||||
}
|
}
|
||||||
@ -1556,8 +1567,6 @@ static _Return_type_success_(return != NULL) WINTUN_ADAPTER *CreateAdapter(
|
|||||||
}
|
}
|
||||||
LastError = ERROR_SUCCESS;
|
LastError = ERROR_SUCCESS;
|
||||||
|
|
||||||
cleanupTcpipInterfaceRegKey:
|
|
||||||
RegCloseKey(TcpipInterfaceRegKey);
|
|
||||||
cleanupTcpipAdapterRegKey:
|
cleanupTcpipAdapterRegKey:
|
||||||
RegCloseKey(TcpipAdapterRegKey);
|
RegCloseKey(TcpipAdapterRegKey);
|
||||||
cleanupAdapter:
|
cleanupAdapter:
|
||||||
|
Loading…
Reference in New Issue
Block a user