dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.35k stars 4.74k forks source link

Failing assert in SystemUnicastIPAddressInformation.PrefixLengthToSubnetMask #18691

Closed stephentoub closed 4 years ago

stephentoub commented 8 years ago

@geoffkizer is hitting the following assert in a bunch of tests when building/running corefx tests locally on Windows:

        <failure exception-type="System.Diagnostics.Debug+DebugAssertException">
          <message><![CDATA[System.Diagnostics.Debug+DebugAssertException : \r\n\r\n   at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)\r\n   at System.Environment.get_StackTrace()\r\n   at System.Diagnostics.Debug.Assert(Boolean condition, String message, String detailMessage)\r\n   at System.Net.NetworkInformation.SystemUnicastIPAddressInformation.PrefixLengthToSubnetMask(Byte prefixLength, AddressFamily family) in corefx\src\System.Net.NetworkInformation\src\System\Net\NetworkInformation\SystemUnicastIPAddressInformation.cs:line 170\r\n   at System.Net.NetworkInformation.SystemUnicastIPAddressInformation..ctor(IpAdapterUnicastAddress adapterAddress) in corefx\src\System.Net.NetworkInformation\src\System\Net\NetworkInformation\SystemUnicastIPAddressInformation.cs:line 40\r\n   at System.Net.NetworkInformation.SystemUnicastIPAddressInformation.MarshalUnicastIpAddressInformationCollection(IntPtr ptr) in corefx\src\System.Net.NetworkInformation\src\System\Net\NetworkInformation\SystemUnicastIPAddressInformation.cs:line 146\r\n   at System.Net.NetworkInformation.SystemIPInterfaceProperties..ctor(FIXED_INFO fixedInfo, IpAdapterAddresses ipAdapterAddresses) in corefx\src\System.Net.NetworkInformation\src\System\Net\NetworkInformation\SystemIPInterfaceProperties.cs:line 42\r\n   at System.Net.NetworkInformation.SystemNetworkInterface..ctor(FIXED_INFO fixedInfo, IpAdapterAddresses ipAdapterAddresses) in corefx\src\System.Net.NetworkInformation\src\System\Net\NetworkInformation\SystemNetworkInterface.cs:line 26\r\n   at System.Net.NetworkInformation.SystemNetworkInterface.GetNetworkInterfaces() in corefx\src\System.Net.NetworkInformation\src\System\Net\NetworkInformation\SystemNetworkInterface.cs:line 120\r\n   at System.Net.NetworkInformation.NetworkInterfacePal.GetAllNetworkInterfaces() in corefx\src\System.Net.NetworkInformation\src\System\Net\NetworkInformation\NetworkInterfacePal.Windows.cs:line 12\r\n   at System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces() in corefx\src\System.Net.NetworkInformation\src\System\Net\NetworkInformation\NetworkInterface.cs:line 15\r\n   at System.Net.NetworkInformation.Tests.IPInterfacePropertiesTest_Windows.IPv6ScopeId_GetLinkLevel_MatchesIndex() in corefx\src\System.Net.NetworkInformation\tests\FunctionalTests\IPInterfacePropertiesTest_Windows.cs:line 181\r\n   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)\r\n   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)\r\n   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)\r\n   at Xunit.Sdk.TestInvoker`1.CallTestMethod(Object testClassInstance) in C:\BuildAgent\work\cb37e9acf085d108\src\xunit.execution\Sdk\Frameworks\Runners\TestInvoker.cs:line 147\r\n   at Xunit.Sdk.TestInvoker`1.<>c__DisplayClass46_1.<<InvokeTestMethodAsync>b__1>d.MoveNext() in C:\BuildAgent\work\cb37e9acf085d108\src\xunit.execution\Sdk\Frameworks\Runners\TestInvoker.cs:line 224\r\n   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine)\r\n   at Xunit.Sdk.TestInvoker`1.<>c__DisplayClass46_1.<InvokeTestMethodAsync>b__1()\r\n   at Xunit.Sdk.ExecutionTimer.<AggregateAsync>d__4.MoveNext() in C:\BuildAgent\work\cb37e9acf085d108\src\xunit.execution\Sdk\Frameworks\ExecutionTimer.cs:line 48\r\n   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine)\r\n   at Xunit.Sdk.ExecutionTimer.AggregateAsync(Func`1 asyncAction)\r\n   at Xunit.Sdk.ExceptionAggregator.<RunAsync>d__9.MoveNext() in C:\BuildAgent\work\cb37e9acf085d108\src\xunit.core\Sdk\ExceptionAggregator.cs:line 90\r\n   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine)\r\n   at Xunit.Sdk.ExceptionAggregator.RunAsync(Func`1 code)\r\n   at Xunit.Sdk.TestInvoker`1.<InvokeTestMethodAsync>d__46.MoveNext() in C:\BuildAgent\work\cb37e9acf085d108\src\xunit.execution\Sdk\Frameworks\Runners\TestInvoker.cs:line 208\r\n   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)\r\n   at Xunit.Sdk.TestInvoker`1.InvokeTestMethodAsync(Object testClassInstance)\r\n   at Xunit.Sdk.TestInvoker`1.<<RunAsync>b__45_0>d.MoveNext() in C:\BuildAgent\work\cb37e9acf085d108\src\xunit.execution\Sdk\Frameworks\Runners\TestInvoker.cs:line 173\r\n   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)\r\n   at Xunit.Sdk.TestInvoker`1.<RunAsync>b__45_0()\r\n   at Xunit.Sdk.ExceptionAggregator.<RunAsync>d__10`1.MoveNext() in C:\BuildAgent\work\cb37e9acf085d108\src\xunit.core\Sdk\ExceptionAggregator.cs:line 107\r\n   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)\r\n   at Xunit.Sdk.ExceptionAggregator.RunAsync[T](Func`1 code)\r\n   at Xunit.Sdk.XunitTestRunner.<InvokeTestAsync>d__4.MoveNext() in C:\BuildAgent\work\cb37e9acf085d108\src\xunit.execution\Sdk\Frameworks\Runners\XunitTestRunner.cs:line 67\r\n   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)\r\n   at Xunit.Sdk.XunitTestRunner.InvokeTestAsync(ExceptionAggregator aggregator)\r\n   at Xunit.Sdk.ExceptionAggregator.<RunAsync>d__10`1.MoveNext() in C:\BuildAgent\work\cb37e9acf085d108\src\xunit.core\Sdk\ExceptionAggregator.cs:line 0\r\n   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)\r\n   at Xunit.Sdk.ExceptionAggregator.RunAsync[T](Func`1 code)\r\n   at Xunit.Sdk.TestRunner`1.<RunAsync>d__43.MoveNext() in C:\BuildAgent\work\cb37e9acf085d108\src\xunit.execution\Sdk\Frameworks\Runners\TestRunner.cs:line 0\r\n   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)\r\n   at Xunit.Sdk.TestRunner`1.RunAsync()\r\n   at Xunit.Sdk.TestCaseRunner`1.<RunAsync>d__19.MoveNext() in C:\BuildAgent\work\cb37e9acf085d108\src\xunit.execution\Sdk\Frameworks\Runners\TestCaseRunner.cs:line 82\r\n   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)\r\n   at Xunit.Sdk.TestCaseRunner`1.RunAsync()\r\n   at Xunit.Sdk.XunitTestMethodRunner.RunTestCaseAsync(IXunitTestCase testCase) in C:\BuildAgent\work\cb37e9acf085d108\src\xunit.execution\Sdk\Frameworks\Runners\XunitTestMethodRunner.cs:line 45\r\n   at Xunit.Sdk.TestMethodRunner`1.<RunTestCasesAsync>d__32.MoveNext() in C:\BuildAgent\work\cb37e9acf085d108\src\xunit.execution\Sdk\Frameworks\Runners\TestMethodRunner.cs:line 136\r\n   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)\r\n   at Xunit.Sdk.TestMethodRunner`1.RunTestCasesAsync()\r\n   at Xunit.Sdk.TestMethodRunner`1.<RunAsync>d__31.MoveNext() in C:\BuildAgent\work\cb37e9acf085d108\src\xunit.execution\Sdk\Frameworks\Runners\TestMethodRunner.cs:line 106\r\n   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)\r\n   at Xunit.Sdk.TestMethodRunner`1.RunAsync()\r\n   at Xunit.Sdk.TestClassRunner`1.<RunTestMethodsAsync>d__38.MoveNext() in C:\BuildAgent\work\cb37e9acf085d108\src\xunit.execution\Sdk\Frameworks\Runners\TestClassRunner.cs:line 205\r\n   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)\r\n   at Xunit.Sdk.TestClassRunner`1.RunTestMethodsAsync()\r\n   at Xunit.Sdk.TestClassRunner`1.<RunAsync>d__37.MoveNext() in C:\BuildAgent\work\cb37e9acf085d108\src\xunit.execution\Sdk\Frameworks\Runners\TestClassRunner.cs:line 163\r\n   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)\r\n   at Xunit.Sdk.TestClassRunner`1.RunAsync()\r\n   at Xunit.Sdk.TestCollectionRunner`1.<RunTestClassesAsync>d__28.MoveNext() in C:\BuildAgent\work\cb37e9acf085d108\src\xunit.execution\Sdk\Frameworks\Runners\TestCollectionRunner.cs:line 130\r\n   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)\r\n   at Xunit.Sdk.TestCollectionRunner`1.RunTestClassesAsync()\r\n   at Xunit.Sdk.TestCollectionRunner`1.<RunAsync>d__27.MoveNext() in C:\BuildAgent\work\cb37e9acf085d108\src\xunit.execution\Sdk\Frameworks\Runners\TestCollectionRunner.cs:line 101\r\n   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)\r\n   at Xunit.Sdk.TestCollectionRunner`1.RunAsync()\r\n   at Xunit.Sdk.XunitTestAssemblyRunner.<>c__DisplayClass14_2.<RunTestCollectionsAsync>b__3() in C:\BuildAgent\work\cb37e9acf085d108\src\xunit.execution\Sdk\Frameworks\Runners\XunitTestAssemblyRunner.cs:line 179\r\n   at System.Threading.Tasks.Task`1.InnerInvoke()\r\n   at System.Threading.Tasks.Task.Execute()\r\n   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)\r\n   at System.Threading.Tasks.Task.ExecuteEntry(Boolean bPreventDoubleExecution)\r\n   at Xunit.Sdk.MaxConcurrencySyncContext.RunOnSyncContext(SendOrPostCallback callback, Object state) in C:\BuildAgent\work\cb37e9acf085d108\src\xunit.execution\Sdk\MaxConcurrencySyncContext.cs:line 107\r\n   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n   at Xunit.Sdk.MaxConcurrencySyncContext.WorkerThreadProc() in C:\BuildAgent\work\cb37e9acf085d108\src\xunit.execution\Sdk\MaxConcurrencySyncContext.cs:line 89\r\n   at Xunit.Sdk.XunitWorkerThread.<>c.<QueueUserWorkItem>b__5_0(Object _) in C:\BuildAgent\work\cb37e9acf085d108\src\common\XunitWorkerThread.cs:line 37\r\n   at System.Threading.Tasks.Task.Execute()\r\n   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)\r\n   at System.Threading.Tasks.Task.ExecuteEntry(Boolean bPreventDoubleExecution)\r\n   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)]]></message>
          <stack-trace><![CDATA[   at System.Diagnostics.Debug.WindowsDebugLogger.ShowAssertDialog(String stackTrace, String message, String detailMessage)
   at System.Net.NetworkInformation.SystemUnicastIPAddressInformation.PrefixLengthToSubnetMask(Byte prefixLength, AddressFamily family) in corefx\src\System.Net.NetworkInformation\src\System\Net\NetworkInformation\SystemUnicastIPAddressInformation.cs:line 170
   at System.Net.NetworkInformation.SystemUnicastIPAddressInformation..ctor(IpAdapterUnicastAddress adapterAddress) in corefx\src\System.Net.NetworkInformation\src\System\Net\NetworkInformation\SystemUnicastIPAddressInformation.cs:line 40
   at System.Net.NetworkInformation.SystemUnicastIPAddressInformation.MarshalUnicastIpAddressInformationCollection(IntPtr ptr) in corefx\src\System.Net.NetworkInformation\src\System\Net\NetworkInformation\SystemUnicastIPAddressInformation.cs:line 146
   at System.Net.NetworkInformation.SystemIPInterfaceProperties..ctor(FIXED_INFO fixedInfo, IpAdapterAddresses ipAdapterAddresses) in corefx\src\System.Net.NetworkInformation\src\System\Net\NetworkInformation\SystemIPInterfaceProperties.cs:line 42
   at System.Net.NetworkInformation.SystemNetworkInterface..ctor(FIXED_INFO fixedInfo, IpAdapterAddresses ipAdapterAddresses) in corefx\src\System.Net.NetworkInformation\src\System\Net\NetworkInformation\SystemNetworkInterface.cs:line 162
   at System.Net.NetworkInformation.SystemNetworkInterface.GetNetworkInterfaces() in corefx\src\System.Net.NetworkInformation\src\System\Net\NetworkInformation\SystemNetworkInterface.cs:line 120
   at System.Net.NetworkInformation.NetworkInterfacePal.GetAllNetworkInterfaces() in corefx\src\System.Net.NetworkInformation\src\System\Net\NetworkInformation\NetworkInterfacePal.Windows.cs:line 12
   at System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces() in corefx\src\System.Net.NetworkInformation\src\System\Net\NetworkInformation\NetworkInterface.cs:line 15
   at System.Net.NetworkInformation.Tests.IPInterfacePropertiesTest_Windows.IPv6ScopeId_GetLinkLevel_MatchesIndex() in corefx\src\System.Net.NetworkInformation\tests\FunctionalTests\IPInterfacePropertiesTest_Windows.cs:line 181]]></stack-trace>
        </failure>

cc: @cipop, @davidsh, @mellinoe

davidsh commented 8 years ago

What version of Windows is this happening on?

stephentoub commented 8 years ago

@geoffkizer, can you comment on your OS details for @davidsh? (I just pulled this from the log Geoffrey sent to me.)

stephentoub commented 8 years ago

@davidsh, I'm hitting this, too. Version 1607 (OS Build 14393.321)

davidsh commented 8 years ago

cc: @CIPop

CIPop commented 8 years ago

If it doesn't happen to everybody, this has could be triggered by something within your network adapter configuration. Can you repro it consistently after the code has been changed to Debug.Assert?

Please attach the output of ipconfig /all. What are the values for the locals, especially addressBytes and prefixLength ?

geoffkizer commented 8 years ago

I'm running Windows 10, version 1607, build 14393.321 also.

Windows IP Configuration

   Host Name . . . . . . . . . . . . : MININT-DFS3MTO
   Primary Dns Suffix  . . . . . . . : redmond.corp.microsoft.com
   Node Type . . . . . . . . . . . . : Hybrid
   IP Routing Enabled. . . . . . . . : No
   WINS Proxy Enabled. . . . . . . . : No
   DNS Suffix Search List. . . . . . : corp.microsoft.com

Ethernet adapter Ethernet:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Intel(R) Ethernet Connection I217-LM
   Physical Address. . . . . . . . . : 54-EE-75-49-B2-D2
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes

PPP adapter MSIT AutoVPN:

   Connection-specific DNS Suffix  . : corp.microsoft.com
   Description . . . . . . . . . . . : MSIT AutoVPN
   Physical Address. . . . . . . . . :
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes
   IPv4 Address. . . . . . . . . . . : 172.19.31.196(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.255
   Default Gateway . . . . . . . . . :
   DNS Servers . . . . . . . . . . . : 157.54.10.28
                                       157.54.14.162
   NetBIOS over Tcpip. . . . . . . . : Disabled

Wireless LAN adapter Local Area Connection* 3:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Microsoft Wi-Fi Direct Virtual Adapter
   Physical Address. . . . . . . . . : CC-3D-82-73-74-AA
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes

Wireless LAN adapter Wi-Fi:

   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Intel(R) Dual Band Wireless-AC 7260
   Physical Address. . . . . . . . . : CC-3D-82-73-74-A9
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   Link-local IPv6 Address . . . . . : fe80::6cc0:ca26:7b15:bfc3%2(Preferred)
   IPv4 Address. . . . . . . . . . . : 192.168.1.4(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Lease Obtained. . . . . . . . . . : Thursday, October 20, 2016 3:33:08 PM
   Lease Expires . . . . . . . . . . : Saturday, October 22, 2016 10:23:23 AM
   Default Gateway . . . . . . . . . : 192.168.1.1
   DHCP Server . . . . . . . . . . . : 192.168.1.1
   DHCPv6 IAID . . . . . . . . . . . : 63716738
   DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-1D-39-CB-E2-54-EE-75-49-B2-D2
   DNS Servers . . . . . . . . . . . : 199.27.176.25
                                       199.27.176.26
                                       192.168.1.1
   NetBIOS over Tcpip. . . . . . . . : Enabled

Ethernet adapter Bluetooth Network Connection:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Bluetooth PAN HelpText
   Physical Address. . . . . . . . . : CC-3D-82-73-74-AD
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes

Tunnel adapter isatap.{00E6321A-A5A1-420A-B953-B75075CBC39C}:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Microsoft ISATAP Adapter
   Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes

Tunnel adapter Local Area Connection* 4:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Microsoft Teredo Tunneling Adapter
   Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes

Tunnel adapter isatap.corp.microsoft.com:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . : corp.microsoft.com
   Description . . . . . . . . . . . : Microsoft ISATAP Adapter dotnet/corefx#2
   Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes
CIPop commented 8 years ago

https://github.com/dotnet/corefx/blob/bffef76f6af208e2042a2f27bc081ee908bb390b/src/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemUnicastIPAddressInformation.cs#L170

The assert is incorrect: Debug.Assert(prefixLength < (addressBytes.Length * 8));

This will fail for the /32 (HOST) CIDR:

   Subnet Mask . . . . . . . . . . . : 255.255.255.255

Should be <= instead of <.