From 1b06f3f0ae3302ddea845c9c71608b2abaa4cd0b Mon Sep 17 00:00:00 2001 From: Yegor Jbanov Date: Thu, 18 Aug 2016 16:53:38 -0700 Subject: [PATCH] self-destruct when a task goes bad The Dart VM sometimes retains phantom "ports" and is unable to exit when child processes are force-quit. --- agent/lib/src/commands/run.dart | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/agent/lib/src/commands/run.dart b/agent/lib/src/commands/run.dart index 707e5c0ea5..cac6909319 100644 --- a/agent/lib/src/commands/run.dart +++ b/agent/lib/src/commands/run.dart @@ -77,6 +77,14 @@ class RunCommand extends Command { } finally { await forceQuitRunningProcesses(); } + + if (exitCode != 0) { + // Force-quitting child processes sometimes causes the Dart VM to fail to + // exit. So we give a 2-second grace period for any pending cleanups, then + // self-destruct. + await new Future.delayed(const Duration(seconds: 2)); + exit(exitCode); + } } }