Skip to content

Commit e9fa8a3

Browse files
Martin Bauligmarek-safar
authored andcommitted
WebConnection.Connect() needs to probe all IP addresses.
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".
1 parent 7126712 commit e9fa8a3

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

mcs/class/System/System.Net/WebConnection.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ async Task Connect (WebOperation operation, CancellationToken cancellationToken)
141141
#endif
142142
}
143143

144+
Exception connectException = null;
145+
144146
foreach (IPAddress address in hostEntry.AddressList) {
145147
operation.ThrowIfDisposed (cancellationToken);
146148

@@ -169,15 +171,21 @@ async Task Connect (WebOperation operation, CancellationToken cancellationToken)
169171
throw;
170172
} catch (Exception exc) {
171173
Interlocked.Exchange (ref socket, null)?.Close ();
172-
throw GetException (WebExceptionStatus.ConnectFailure, exc);
174+
// Something went wrong, but we might have multiple IP Addresses
175+
// and need to probe them all.
176+
connectException = GetException (WebExceptionStatus.ConnectFailure, exc);
177+
continue;
173178
}
174179
}
175180

176181
if (socket != null)
177182
return;
178183
}
179184

180-
throw GetException (WebExceptionStatus.ConnectFailure, null);
185+
if (connectException == null)
186+
connectException = GetException (WebExceptionStatus.ConnectFailure, null);
187+
188+
throw connectException;
181189
}
182190

183191
#if MONO_WEB_DEBUG

0 commit comments

Comments
 (0)