Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(526)

Unified Diff: lib/http_multi_server.dart

Issue 992843002: Eventually stop retrying port allocation if it fails repeatedly. (Closed) Base URL: git@github.com:dart-lang/http_multi_server@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/http_multi_server.dart
diff --git a/lib/http_multi_server.dart b/lib/http_multi_server.dart
index fc874550482a4078969038ecbb99fe1ac9126ed0..36d583f78d8c495a0e9062d4c344eea5e75895ca 100644
--- a/lib/http_multi_server.dart
+++ b/lib/http_multi_server.dart
@@ -128,7 +128,10 @@ class HttpMultiServer extends StreamView<HttpRequest> implements HttpServer {
/// [bind] should forward to either [HttpServer.bind] or
/// [HttpServer.bindSecure].
static Future<HttpServer> _loopback(int port,
- Future<HttpServer> bind(InternetAddress address, int port)) {
+ Future<HttpServer> bind(InternetAddress address, int port),
+ [int remainingRetries]) {
+ if (remainingRetries == null) remainingRetries = 5;
+
return Future.wait([
supportsIpV6,
bind(InternetAddress.LOOPBACK_IP_V4, port)
@@ -147,12 +150,13 @@ class HttpMultiServer extends StreamView<HttpRequest> implements HttpServer {
if (error is! SocketException) throw error;
if (error.osError.errno != _addressInUseErrno) throw error;
if (port != 0) throw error;
+ if (remainingRetries == 0) throw error;
// A port being available on IPv4 doesn't necessarily mean that the same
// port is available on IPv6. If it's not (which is rare in practice),
// we try again until we find one that's available on both.
v4Server.close();
- return _loopback(port, bind);
+ return _loopback(port, bind, remainingRetries - 1);
});
});
}
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698