coreybutler / node-windows

Windows support for Node.JS scripts (daemons, eventlog, UAC, etc).
Other
2.78k stars 357 forks source link

wrapper.js: reset attempts and log exit code #256

Open clausreinke opened 4 years ago

clausreinke commented 4 years ago

currently, the following lines are dead code as child is null when monitor is called https://github.com/coreybutler/node-windows/blob/accfbd0528ad5148cb6283e5d8f2b407f890dfbc/lib/wrapper.js#L120-L125

This suggests that monitor may not be used as originally intended, and it means that even successful restarts suffer from accumulated delays, keeping the child offline without reason.

Given the ressource limitations on this project, I would suggest a minor fix: after the fork (https://github.com/coreybutler/node-windows/blob/accfbd0528ad5148cb6283e5d8f2b407f890dfbc/lib/wrapper.js#L162) add

 if (child && child.pid) {
    // reset attempts and wait time
    attempts = 0;
    wait = argv.w * 1000;
  }

Also, please don't hide the child's exit code - it is sometimes the only available clue to what went wrong.

https://github.com/coreybutler/node-windows/blob/accfbd0528ad5148cb6283e5d8f2b407f890dfbc/lib/wrapper.js#L165-L166

log.warn(argv.f+' stopped running with code: '+code.toString(16));