﻿id	summary	reporter	owner	description	type	status	component	version	resolution	keywords	cc	guest	host
14040	Windows host-only adapter creation fails due to slow background processing	Jiri Hruska		"I was debugging why Xamarin Android Player could not prepare a VM for me and determined the failure to be in the host-only adapter creation, isolating the problem to this:

{{{
C:\Program Files\Oracle\VirtualBox\>VBoxManage.exe hostonlyif create
0%...
Progress state: E_FAIL
VBoxManage.exe: error: Failed to create the host-only adapter
VBoxManage.exe: error: Code E_FAIL (0x80004005) - Unspecified error (extended info not available)
VBoxManage.exe: error: Context: ""int __cdecl handleCreate(struct HandlerArg *,int,int *)"" at line 66 of file VBoxManageHostonly.cpp
}}}

After some time spent in the debugger, I've found the real error to be `CO_E_CLASSSTRING` (Invalid class string), naturally returned by some `CLSIDFromString()` API call. Interestingly enough, the input GUID string contained garbage only.

Further debugging revealed a data race in `VBoxNetCfgWinCreateHostOnlyNetworkInterface()`. By the time `RegQueryValueExW(..., ""NetCfgInstanceId"", ...)` is called, the network device might still not be fully constructed by another process and this registry value might not be present yet. Because the result of this operation is effectively ignored, the program silently continues and the function fails only later due to the GUID being invalid.

A proof from Process Monitor - it took the system ~0.4 seconds more to write the value:
{{{
03:11:01.9426053	VBoxSVC.exe	15024	RegQueryValue	HKLM\System\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0018\NetCfgInstanceId	NAME NOT FOUND	Length: 144
03:11:02.3592881	svchost.exe	1140	RegSetValue	HKLM\System\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0018\NetCfgInstanceId	SUCCESS	Type: REG_SZ, Length: 78, Data: {F4CCBF3A-4C8B-4FE7-A659-725C3DF52E69}
}}}

Waiting in the debugger for a while before the `RegQueryValueExW()` call helped and I was able to create host-only network adapters fine.

Setting as priority minor because:
* it happened on a pre-release OS (Windows 10 preview build 10052)
* it happened on a pre-release VirtualBox (5.0.0_BETA1 r99371).

On the other hand, I submitted a ticket anyway because:
* the race is still a bug and can possibly crash the program, it might have been working with a little bit of luck only
* it seems the relevant VBox code has not been changed for the current beta
* I hear there was some refactoring done in Windows 10 regarding network adapters, this might show up later for more people"	defect	reopened	network/hostif	VirtualBox 5.0.0		win10		all	Windows
