Unitech / Unitech/pm2

PM2 API ignores maxRestarts and restartDelay configuration

Open
#2,716 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

P3: Medium S: Open for PR SYS: API T: Bug
Dominant language
JavaScript
Stars
43.3k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Description

So, I have a worker which tries to grab some data from web. I want to restart it on every fail and log the error. To monitor the worker process I use pm2. The simplified sample looks like:

index.js

const pm2 = require('pm2');

pm2.connect(function(err) {
    if (err) {
          console.error(err);
          process.exit(2);
        }
    pm2.start({
          script    : 'populate.js',
          exec_mode : 'cluster',
          instances : 1,
          autorestart: true,
          max_memory_restart : '100M',
          max_restarts: 1000 // or maxRestarts: 1000 documentation is inconsistent here
    }, function(err) {
      if (err) return console.error('Error while launching applications', err.stack || err);
      console.log('PM2 and application has been succesfully started');
      pm2.launchBus(function(err, bus) {
        console.log('[PM2] Log streaming started');
        bus.on('log:out', function(packet) {
         console.log('[App:%s] %s', packet.process.name, packet.data);
        });
        bus.on('log:err', function(packet) {
          console.error('[App:%s][Err] %s', packet.process.name, packet.data);
        });
      });
    });
});

populate.js

const Promise = require('bluebird');

function populate() { // this function is just for illustration purpose
  return Promise.delay(500)
    .then(()=> Math.random() >= 0.5)
    .then(flag => {
      if(flag) {
        console.log('populates db')
        return populate()
      } else {
        throw new Error('something wrong')
      }
    })

}
populate()

But when I run script it doesn't restart scrapper more then 3 times(I expect 1000 times)

>    node index.js

PM2 and application has been succesfully started
[PM2] Log streaming started
[App:populate] populates db


[App:populate][Err]
You have triggered an unhandledRejection, you may
[App:populate][Err]
You have triggered an unhandledRejection, you may
[App:populate] populates db

[App:populate][Err]
You have triggered an unhandledRejection, you may
[App:populate][Err]
You have triggered an unhandledRejection, you may
Software versions used
OS         : os x 10.10.5
node.js    : v6.3.1
PM2        : pm2@2.4.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior with the index.js and populate.js samples, starting at the pm2.start call and its max_restarts configuration. Compare the documented maxRestarts spelling and restartDelay handling, then verify that the worker honors both settings and restarts for the configured limit.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
backend, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.