[ Service ] Fix issue where VM would hang in ServiceIsolate::Shutdown if
shutdown immediately after starting up
Running the VM with arguments that cause a quick failure _after_ the
service isolate is started could result in the VM service starting and
attempting to register a signal handler after the VM has started
shutting down. The open port held by the signal handler prevented the
message handler from shutting down, resulting in the main thread being
blocked on a monitor in ServiceIsolate::Shutdown.
Could be reproduced with the following commands:
$ rm out/DebugX64/dartdev.dart.snapshot
$ out/DebugX64/dart --observe hello_world.dart
Change-Id: I70ddff73c98151bd7eff22064a23f897b4d6299f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/156923
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
diff --git a/sdk/lib/_internal/vm/bin/vmservice_io.dart b/sdk/lib/_internal/vm/bin/vmservice_io.dart
index aea026b..e84c8f8 100644
--- a/sdk/lib/_internal/vm/bin/vmservice_io.dart
+++ b/sdk/lib/_internal/vm/bin/vmservice_io.dart
@@ -222,6 +222,12 @@
Timer? _registerSignalHandlerTimer;
_registerSignalHandler() {
+ if (VMService().isExiting) {
+ // If the VM started shutting down we don't want to register this signal
+ // handler, otherwise we'll cause the VM to hang after killing the service
+ // isolate.
+ return;
+ }
_registerSignalHandlerTimer = null;
if (_signalWatch == null) {
// Cannot register for signals.