Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Safe async exit after an exception #354

Closed
simonepri opened this issue Aug 1, 2017 · 1 comment
Closed

Safe async exit after an exception #354

simonepri opened this issue Aug 1, 2017 · 1 comment

Comments

@simonepri
Copy link

Problem

There's no way to know if is safe to kill the process or if raven is sending data.

Scenario

Imagine that somewere in the code I want to kill my server, but in the meanwhile raven is sending some data to Sentry.

Workaround

let exceptions = 0;
process.on('uncaughtException', () => {
    exceptions++;
});

raven
    .config(dns, opts)
    .install(handler); // Since we have passed a custom handler the process does not exit automatically, this is good :)

function handler(err) {
  exceptions--;
  // Log the erro on the console
  console.log(err);
}

function close(cb) {
  const interval = setInterval(closed, 100);
    closed();

    function closed() {
      if (exceptions === 0) {
        clearInterval(interval);
        cb();
      }
    }
  });
}


// Somewhere else
close(() => {
  // This is called after all errors are been sent to sentry. Now you can kill the process safetly.
  process.exit(1);
});
@kamilogorek
Copy link
Contributor

Duplicate of #338

@kamilogorek kamilogorek marked this as a duplicate of #338 Jan 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants