metarhia/impress

Impress doesn't restart worker if it crush on "JS heap out of memory"

MarhiievHE opened this issue · 0 comments

Impress and Node.js versions

impress: 3.0.13, node: 18 & 20

Platform

No response

Describe the bug

Impress will not restart the worker if it crashes with error code ERR_WORKER_OUT_OF_MEMORY. This error is not caught by the worker and goes to the uncaught errors listener here:

process.on('uncaughtException', logError('Uncaught exception'));
.
Since we don't catch worker errors, this "ERR_WORKER_OUT_OF_MEMORY" exit code does not go to the "exit" event listener:
worker.on('exit', (code) => {
.

To Reproduce

Create endpoint that make memory leak, to example:

({
  access: 'public',
  method: async () => {
    const array = [];

    while (true) {
      array.push(new Array(1000000));
    }
  },
});

Expected behavior

Impress should restart the fallen worker.

Screenshots

image image image

Additional context

To fix it, all you need to do is to add a listener to the error events of the worker such as this one:

  worker.on('error', (error) => {
    impress.console.error('Error in worker : ', error);
  });
image