Skip to content

Commit e6d3a45

Browse files
a-sivacommit-bot@chromium.org
authored andcommitted
[VM] Fix for issue 34839 Service isolate hangs during shutdown if
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]>
1 parent 770436d commit e6d3a45

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

runtime/bin/vmservice/server.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,12 @@ class Server {
373373
}
374374
await new Future<Null>.delayed(const Duration(seconds: 1));
375375
}
376+
if (_service.isExiting) {
377+
serverPrint('Observatory HTTP server exiting before listening as '
378+
'vm service has received exit request\n');
379+
await shutdown(true);
380+
return this;
381+
}
376382
_server.listen(_requestHandler, cancelOnError: true);
377383
serverPrint('Observatory listening on $serverAddress');
378384
if (Platform.isFuchsia) {

sdk/lib/vmservice/vmservice.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ class VMService extends MessageRouter {
204204
/// Collection of currently running isolates.
205205
RunningIsolates runningIsolates = new RunningIsolates();
206206

207+
/// Flag to indicate VM service is exiting.
208+
bool isExiting = false;
209+
207210
/// A port used to receive events from the VM.
208211
final RawReceivePort eventPort;
209212

@@ -323,6 +326,8 @@ class VMService extends MessageRouter {
323326
}
324327

325328
Future _exit() async {
329+
isExiting = true;
330+
326331
// Stop the server.
327332
if (VMServiceEmbedderHooks.serverStop != null) {
328333
await VMServiceEmbedderHooks.serverStop();
@@ -342,6 +347,7 @@ class VMService extends MessageRouter {
342347
if (VMServiceEmbedderHooks.cleanup != null) {
343348
await VMServiceEmbedderHooks.cleanup();
344349
}
350+
345351
// Notify the VM that we have exited.
346352
_onExit();
347353
}

0 commit comments

Comments
 (0)