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

Safe async exit after an exception #354

Closed
@simonepri

Description

@simonepri

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);
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions