From e462195cac7c1537feefaa3c8db46db9604be5bb Mon Sep 17 00:00:00 2001 From: wfurt Date: Tue, 29 Jan 2019 11:59:12 -0800 Subject: [PATCH 1/3] add instrumentation for #32797 --- .../tests/PalTests/NameResolutionPalTests.cs | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs b/src/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs index 28be0af6abff..0d30aec94037 100644 --- a/src/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs +++ b/src/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs @@ -35,7 +35,6 @@ public void TryGetAddrInfo_LocalHost() Assert.NotNull(hostEntry.Aliases); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotArm64Process))] // [ActiveIssue(32797)] public void TryGetAddrInfo_HostName() { string hostName = NameResolutionPal.GetHostName(); @@ -44,12 +43,21 @@ public void TryGetAddrInfo_HostName() IPHostEntry hostEntry; int nativeErrorCode; SocketError error = NameResolutionPal.TryGetAddrInfo(hostName, out hostEntry, out nativeErrorCode); - if (error == SocketError.HostNotFound && (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX))) + if (error == SocketError.HostNotFound && (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD))) { // On Unix, we are not guaranteed to be able to resove the local host. The ability to do so depends on the // machine configurations, which varies by distro and is often inconsistent. return; } + + // Temporary instrumentation for #32797 + if (error == SocketError.TryAgain && (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD))) + { + if (error != SocketError.TryAgain) + { + throw new InvalidOperationException("Name resolution failure preventable with retry"); + } + } Assert.Equal(SocketError.Success, error); Assert.NotNull(hostEntry); @@ -92,7 +100,6 @@ public void TryGetAddrInfo_LocalHost_TryGetNameInfo() Assert.NotNull(name); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotArm64Process))] // [ActiveIssue(32797)] public void TryGetAddrInfo_HostName_TryGetNameInfo() { string hostName = NameResolutionPal.GetHostName(); @@ -105,10 +112,19 @@ public void TryGetAddrInfo_HostName_TryGetNameInfo() { // On Unix, getaddrinfo returns host not found, if all the machine discovery settings on the local network // is turned off. Hence dns lookup for it's own hostname fails. - Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX)); + Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD)); return; } + // Temporary instrumentation for #32797 + if (error == SocketError.TryAgain && (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD))) + { + if (error != SocketError.TryAgain) + { + throw new InvalidOperationException("Name resolution failure preventable with retry"); + } + } + Assert.Equal(SocketError.Success, error); Assert.NotNull(hostEntry); From 32f26f8c15560f386ca4add70e968f4c3ebb35ae Mon Sep 17 00:00:00 2001 From: wfurt Date: Tue, 29 Jan 2019 12:08:24 -0800 Subject: [PATCH 2/3] actually retry the lookup --- .../tests/PalTests/NameResolutionPalTests.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs b/src/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs index 73067728d616..59e8abcc7cb4 100644 --- a/src/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs +++ b/src/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs @@ -53,6 +53,7 @@ public void TryGetAddrInfo_HostName() // Temporary instrumentation for #32797 if (error == SocketError.TryAgain && Environment.OSVersion.Platform == PlatformID.Unix) { + error = NameResolutionPal.TryGetAddrInfo(hostName, out hostEntry, out nativeErrorCode); if (error != SocketError.TryAgain) { throw new InvalidOperationException("Name resolution failure preventable with retry"); @@ -119,6 +120,7 @@ public void TryGetAddrInfo_HostName_TryGetNameInfo() // Temporary instrumentation for #32797 if (error == SocketError.TryAgain && (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD))) { + error = NameResolutionPal.TryGetAddrInfo(hostName, out hostEntry, out nativeErrorCode); if (error != SocketError.TryAgain) { throw new InvalidOperationException("Name resolution failure preventable with retry"); From 28ffd6ba0bf7e0bc72c9e13b1ad74fadb382851f Mon Sep 17 00:00:00 2001 From: wfurt Date: Tue, 29 Jan 2019 12:41:15 -0800 Subject: [PATCH 3/3] use PlatformID.Unix --- .../tests/PalTests/NameResolutionPalTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs b/src/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs index 59e8abcc7cb4..21008a3e0376 100644 --- a/src/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs +++ b/src/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs @@ -118,7 +118,7 @@ public void TryGetAddrInfo_HostName_TryGetNameInfo() } // Temporary instrumentation for #32797 - if (error == SocketError.TryAgain && (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD))) + if (error == SocketError.TryAgain && Environment.OSVersion.Platform == PlatformID.Unix) { error = NameResolutionPal.TryGetAddrInfo(hostName, out hostEntry, out nativeErrorCode); if (error != SocketError.TryAgain)