Skip to content

Commit

Permalink
#3134 double callback fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Unitech committed Sep 14, 2017
1 parent f1c24d4 commit f70850f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- #3150 fix watchdog on agent
- #3001 dump-backup feature
- #3134 edge case error handling
- #3096 fix module installation
- #3085 honor every pm2 args on restart
- #3046 better error message if PM2 is misconfigured
Expand Down
16 changes: 13 additions & 3 deletions lib/Utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,24 @@ var Utility = module.exports = {

flows.push(function(next){
var file = stds[io];

// if file contains ERR or /dev/null, dont try to create stream since he dont want logs
if (!file || file.indexOf('NULL') > -1 || file.indexOf('/dev/null') > -1)
return next();
stds[io] = fs.createWriteStream(file, {flags: 'a'})
.once('error', function(err){

var error_cb = function(err){
next(err);
})
}

stds[io] = fs.createWriteStream(file, {flags: 'a'})
.once('error', error_cb)
.on('open', function(){
stds[io].removeListener('error', error_cb);

stds[io].on('error', function(err) {
console.error(err);
});

next();
});
stds[io]._file = file;
Expand Down

0 comments on commit f70850f

Please sign in to comment.