Skip to content

Commit

Permalink
WebConnection.Connect() needs to probe all IP addresses.
Browse files Browse the repository at this point in the history
Fix a regression introduced in the new web stack - when connecting
to a DNS host name that resolves to multiple IP addresses, we need
to probe them all.

On iOS, "localhost" will resolve to both "::1" and "127.0.0.1".
  • Loading branch information
Martin Baulig authored and marek-safar committed Feb 12, 2018
1 parent 7126712 commit e9fa8a3
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions mcs/class/System/System.Net/WebConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ async Task Connect (WebOperation operation, CancellationToken cancellationToken)
#endif
}

Exception connectException = null;

foreach (IPAddress address in hostEntry.AddressList) {
operation.ThrowIfDisposed (cancellationToken);

Expand Down Expand Up @@ -169,15 +171,21 @@ async Task Connect (WebOperation operation, CancellationToken cancellationToken)
throw;
} catch (Exception exc) {
Interlocked.Exchange (ref socket, null)?.Close ();
throw GetException (WebExceptionStatus.ConnectFailure, exc);
// Something went wrong, but we might have multiple IP Addresses
// and need to probe them all.
connectException = GetException (WebExceptionStatus.ConnectFailure, exc);
continue;
}
}

if (socket != null)
return;
}

throw GetException (WebExceptionStatus.ConnectFailure, null);
if (connectException == null)
connectException = GetException (WebExceptionStatus.ConnectFailure, null);

throw connectException;
}

#if MONO_WEB_DEBUG
Expand Down

0 comments on commit e9fa8a3

Please sign in to comment.