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

Unified Diff: runtime/bin/vmservice/server.dart

Issue 2772463003: [vm service] Have HTTP server retry binding for 10 seconds (Closed)
Patch Set: Created 3 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/vmservice/server.dart
diff --git a/runtime/bin/vmservice/server.dart b/runtime/bin/vmservice/server.dart
index e659758fd4bd7c37d61580004c0d22c5646636ae..fb272607f56cdd08ebc904fa0e908ddb90f7b3a4 100644
--- a/runtime/bin/vmservice/server.dart
+++ b/runtime/bin/vmservice/server.dart
@@ -323,38 +323,58 @@ class Server {
}
// Startup HTTP server.
- try {
- var address;
- if (Platform.isFuchsia) {
- address = InternetAddress.ANY_IP_V4;
- } else {
- var addresses = await InternetAddress.lookup(_ip);
- // Prefer IPv4 addresses.
- for (var i = 0; i < addresses.length; i++) {
- address = addresses[i];
- if (address.type == InternetAddressType.IP_V4) break;
+ var pollError;
+ var pollStack;
+ Future<bool> poll() async {
+ try {
+ var address;
+ if (Platform.isFuchsia) {
+ address = InternetAddress.ANY_IP_V4;
+ } else {
+ var addresses = await InternetAddress.lookup(_ip);
+ // Prefer IPv4 addresses.
+ for (var i = 0; i < addresses.length; i++) {
+ address = addresses[i];
+ if (address.type == InternetAddressType.IP_V4) break;
+ }
}
+ _server = await HttpServer.bind(address, _port);
+ return true;
+ } catch (e, st) {
+ pollError = e;
+ pollStack = st;
+ return false;
}
- _server = await HttpServer.bind(address, _port);
- _server.listen(_requestHandler, cancelOnError: true);
- serverPrint('Observatory listening on $serverAddress');
- if (Platform.isFuchsia) {
- // Create a file with the port number.
- String tmp = Directory.systemTemp.path;
- String path = "$tmp/dart.services/${_server.port}";
- serverPrint("Creating $path");
- new File(path)..createSync(recursive: true);
+ }
+
+ // poll for the network for ~10 seconds.
+ int attempts = 0;
+ final int maxAttempts = 10;
+ while (!await poll()) {
+ attempts++;
+ serverPrint("Observatory server failed to start after $attempts tries");
+ if (attempts > maxAttempts) {
+ serverPrint('Could not start Observatory HTTP server:\n'
+ '$pollError\n$pollStack\n');
+ _notifyServerState("");
+ onServerAddressChange(null);
+ return this;
}
- // Server is up and running.
- _notifyServerState(serverAddress.toString());
- onServerAddressChange('$serverAddress');
- return this;
- } catch (e, st) {
- serverPrint('Could not start Observatory HTTP server:\n$e\n$st\n');
- _notifyServerState("");
- onServerAddressChange(null);
- return this;
+ await new Future<Null>.delayed(const Duration(seconds: 1));
+ }
+ _server.listen(_requestHandler, cancelOnError: true);
+ serverPrint('Observatory listening on $serverAddress');
+ if (Platform.isFuchsia) {
+ // Create a file with the port number.
+ String tmp = Directory.systemTemp.path;
+ String path = "$tmp/dart.services/${_server.port}";
+ serverPrint("Creating $path");
+ new File(path)..createSync(recursive: true);
}
+ // Server is up and running.
+ _notifyServerState(serverAddress.toString());
+ onServerAddressChange('$serverAddress');
+ return this;
}
Future cleanup(bool force) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698