Star Ford Star Ford - 1 year ago 96
Dart Question

How to detect cause of Dart VM crash

I have two Dart apps running on Amazon (AWS Ubuntu), which are:

  1. Self-hosted http API

  2. Worker that handles background tasks on a timer

Both apps use PostgreSQL. They were occasionally crashing so, in addition to trying to find the root causes, I also implemented a supervisor script that just detects whether those 2 main apps are running and restarts them as needed.

Now the problem I need to solve is that the supervisor script is crashing, or the VM is crashing. It happens every few days.

I don't think it is a memory leak because if I increase the polling rate from 10s to much more often (1 ns), it correctly shows in the Dart Observatory that it exhausts 30MB and then garbage-collects and starts over at low memory usage, and keeps cycling.

I don't think it's an uncaught exception because the infinite loop is completely enclosed in try/catch.

I'm at a loss for what else to try. Is there a VM dump file that can be examined if the VM really crashed? Is there any other technique to debug the root cause? Is Dart just not stable enough to run apps for days at a time?

This is the main part of the code in the supervisor script:

///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) {}

Raj Raj
Answer Source

If you have the observatory up you can get a crash dump with: curl localhost:<your obseratory port>/_getCrashDump

I'm not totally sure if this is related but Process.start returns a future which I don't believe will be caught by your try/catch if it completes with an error...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download