I've built a node.js app which receives incoming requests and forwards these requests to several nodes (virtual machines).
The logic determining where to send each request to is pretty simple, but when using it with multiple CPU's (node processes), I sometimes run into race condition.
Basically, the node.js app receives a "START" command with specific requirements (for example: send to a Linux Node). I keep a list of nodes in an array, loop through the array and pick a node that fits the requirements. I then mark that node as unavailable, so that other START requests do not pick the same node while the first node is using it.
The list is saved in Redis, however when 2 START requests come in with the same requirements, there might be a race condition where my app assigns the same node to both requests, which is not what I want.
I tried using https://github.com/errorception/redis-lock but it's not working very well, still causes occasional problems.
If anyone has recommendations on how to tackle this problem, it'd be greatly appreciated!