From 164c1e2cf6268d953adf459cc4b01c5c305481a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Luthi?= Date: Sun, 19 Sep 2021 10:35:53 +0200 Subject: [PATCH] Properly catch SocketException when calling GetHostEntry Using GetHostEntry instead of GetHostEntryAsync + Wait means the `SocketException` is no longer wrapped inside an `AggregateException`. Also simplify catching the the `AggregateException` in the .NET Standard 1.6 code path by using `GetBaseException()`. --- .../Extensions/CommandExtensions.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Ductus.FluentDocker/Extensions/CommandExtensions.cs b/Ductus.FluentDocker/Extensions/CommandExtensions.cs index 11bddd1..de43d8c 100644 --- a/Ductus.FluentDocker/Extensions/CommandExtensions.cs +++ b/Ductus.FluentDocker/Extensions/CommandExtensions.cs @@ -161,23 +161,33 @@ public static bool IsEmulatedNative() } +#if NETSTANDARD1_6 public static bool IsDockerDnsAvailable() { try { -#if NETSTANDARD1_6 Dns.GetHostEntryAsync("host.docker.internal").Wait(); + return true; + } + catch (Exception ex) when (ex.GetBaseException() is SocketException) + { + return false; + } + } #else + public static bool IsDockerDnsAvailable() + { + try + { Dns.GetHostEntry("host.docker.internal"); -#endif return true; } - catch (AggregateException ex) - when (ex.InnerExceptions.Count == 1 && ex.InnerExceptions[0] is SocketException) + catch (SocketException) { return false; } } +#endif public static bool IsNative() {