0

I'm running some file management tasks through a node script. The node-windows package is included to allow me to run this script as a windows service. I encountered a serious error this morning when I realized that the service had started a duplicate instance of the same script. This is very bad, it corrupted 24-hrs worth of data because both scripts were trying to process the same data sets and ended up shredding them. I've never seen the windows service allow something like this. Has anyone else had this problem or have any idea what is causing it?

  • node-windows will not start a **new** instance of a process without some sort of explicit action from a user. It will restart an existing process if it fails, so it's important to make sure your process fails properly (i.e. the right exit codes), otherwise it can leave the process in a state of limbo. – Corey Mar 03 '17 at 15:52

1 Answers1

0

See my comment about node-windows instances.

The real problem, which is data corruption, doesn't have anything to do with node-windows. The node script should have fault tolerance for this. More specifically, it should be implementing file locking, which is a standard practice to prevent this exact scenario.

There are a couple of file locking modules available. lockfile is what npm uses. There is also another project called proper-lockfile, which solves the problem in a slightly different (more Windows-friendly) way.

Corey
  • 5,133
  • 3
  • 23
  • 24