Skip to content

Commit

Permalink
[VM] Fix for issue 34839 Service isolate hangs during shutdown if
Browse files Browse the repository at this point in the history
     the VM exits before the Observatory server has a chance to
     start listening.

Bug: 34839
Change-Id: I2a5dfe69a197fe054dd041af3ea4e07da736b226
Reviewed-on: https://dart-review.googlesource.com/c/81381
Reviewed-by: Ryan Macnak <[email protected]>
Commit-Queue: Siva Annamalai <[email protected]>
  • Loading branch information
a-siva authored and [email protected] committed Oct 27, 2018
1 parent 770436d commit e6d3a45
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions runtime/bin/vmservice/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,12 @@ class Server {
}
await new Future<Null>.delayed(const Duration(seconds: 1));
}
if (_service.isExiting) {
serverPrint('Observatory HTTP server exiting before listening as '
'vm service has received exit request\n');
await shutdown(true);
return this;
}
_server.listen(_requestHandler, cancelOnError: true);
serverPrint('Observatory listening on $serverAddress');
if (Platform.isFuchsia) {
Expand Down
6 changes: 6 additions & 0 deletions sdk/lib/vmservice/vmservice.dart
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ class VMService extends MessageRouter {
/// Collection of currently running isolates.
RunningIsolates runningIsolates = new RunningIsolates();

/// Flag to indicate VM service is exiting.
bool isExiting = false;

/// A port used to receive events from the VM.
final RawReceivePort eventPort;

Expand Down Expand Up @@ -323,6 +326,8 @@ class VMService extends MessageRouter {
}

Future _exit() async {
isExiting = true;

// Stop the server.
if (VMServiceEmbedderHooks.serverStop != null) {
await VMServiceEmbedderHooks.serverStop();
Expand All @@ -342,6 +347,7 @@ class VMService extends MessageRouter {
if (VMServiceEmbedderHooks.cleanup != null) {
await VMServiceEmbedderHooks.cleanup();
}

// Notify the VM that we have exited.
_onExit();
}
Expand Down

0 comments on commit e6d3a45

Please sign in to comment.