Skip to content

Commit

Permalink
Merge pull request #212 from 0xced/catch-SocketException
Browse files Browse the repository at this point in the history
Properly catch SocketException when calling GetHostEntry
  • Loading branch information
mariotoffia authored Sep 19, 2021
2 parents 2a299b8 + 164c1e2 commit 07eaf15
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions Ductus.FluentDocker/Extensions/CommandExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit 07eaf15

Please sign in to comment.