如何检测Dart VM崩溃的原因

时间:2016-10-17 02:32:39

标签: amazon-web-services dart

我在亚马逊(AWS Ubuntu)上运行了两个Dart应用程序,它们是:

  1. 自托管的http API
  2. 处理计时器后台任务的工作人员
  3. 这两款应用都使用PostgreSQL。他们偶尔崩溃,除了试图找到根本原因之外,我还实现了一个主管脚本,只检测这2个主要应用程序是否正在运行并根据需要重新启动它们。

    现在我需要解决的问题是管理程序脚本崩溃,或者VM崩溃了。它每隔几天发生一次。

    我认为这不是内存泄漏,因为如果我将轮询速率从10s增加到更频繁(1 ns),它会在Dart天文台正确显示它耗尽30MB然后垃圾收集并重新启动在低内存使用情况下,并保持循环。

    我不认为这是一个未被捕获的异常,因为无限循环完全包含在try / catch中。

    我不知道还有什么可尝试的。是否存在VM转储文件,如果VM真的崩溃了可以检查?有没有其他技术来调试根本原因? Dart是否不够稳定,无法一次运行几天的应用程序?

    这是主管脚本中代码的主要部分:

     ///never ending function checks the state of the other processes
     Future pulse() async {
       while (true) {
         sleep(new Duration(milliseconds: 100)); //DEBUG - was seconds:10
         try {
           //detect restart (as signaled from existence of restart.txt)
           File f_restart = new File('restart.txt');
           if (await f_restart.exists()) {
             log("supervisor: restart detected");
             await f_restart.delete();
             await endBoth();
             sleep(new Duration(seconds: 10));
           }
    
           //if restarting or either proc crashed, restart it
           bool apiAlive = await isRunning('api_alive.txt', 3);
           if (!apiAlive) await startApi();
           bool workerAlive = await isRunning('worker_alive.txt', 8);
           if (!workerAlive) await startWorker();
    
           //if it's time to send mail, run that process
           if (utcNow().isAfter(_nextMailUtc)) {
             log("supervisor: starting sendmail");
             Process.start('dart', [rootPath() + '/sendmail.dart'], workingDirectory: rootPath());
             _nextMailUtc = utcNow().add(_mailInterval);
           }
    
         } catch (ex) {}
       }
     }
    

1 个答案:

答案 0 :(得分:1)

如果你有天文台,你可以获得一个崩溃转储: Array.prototype.randomize = function() { var r = /* the algorithm to get a replacement array... */; this.splice(0, r.length, ...r); return this; }

我不完全确定这是否相关,但是...会返回一个我不相信会被你的try / catch抓住的未来,如果它以错误结束...... < / p>