Open m-kostrzewa opened 7 years ago
The workaround is to sleep for 2 seconds after POST request, but this is unacceptable.
When creating a new vswitch via hyper-v manager, it informs you that connectivity may break. I understand similar thing is happening here: when HNS switch is being created, HNS network creation returns success, even though the system is not done dealing with all the configuration changes of vswitch and net adapters.
But as a user of HNS, I care about when the network is ready, not when it is just created. I think HNS should block until everything is up and running. If that is not possible, then I would like to know some workaround, like polling network adapters or something, so that I don't have to use Sleeps in the code.
@m-kostrzewa In our test scripts we do a similar thing to wait of connectivity before invoking new-containernetwork. Example is
function GetConnectedHostIP() { $connectedNics=$x=Get-NetAdapter | ?{$.Status -eq "Up"} | % {$.Name} Get-NetIPAddress | ? {$connectedNics.Contains($.InterfaceAlias) -and $.AddressFamily -eq "IPv4" -and !$.InterfaceAlias.Contains("HNS Internal NIC") -and !$.IPAddress.StartsWith("169") -and !$_.IPAddress.StartsWith("127")} }
function WaitForHostConnectivity {
for ($i=0;$i -lt 20;$i++) { $ip=GetConnectedHostIP if ($ip -ne $null) { return $true } sleep -Milliseconds 300 } return $false
} WaitForHostConnectivity
Issue seems similar to https://github.com/Microsoft/hcsshim/issues/95
There are two test cases and two different errors, but I think the underlying root cause may be the same, that's why I report both errors in the same issue.
Here's the first test case:
net.Dial sometimes fails with:
Powershell script that kinda replicates it (but prints a different error):
I sometimes get error:
which I believe to be a coarse error message encompassing aforementioned
connectex...
error.Here's the second test case, which is very similar to the first one but we don't specify a subnet when creating the HNS network:
This time, we get a HNS error when invoking POST request on HNS:
To replicate via powershell:
Which sometimes returns: