Permalink
Browse files

added _id correlation avoiding roles criss cross on race condition

  • Loading branch information...
1 parent a6b8a5d commit 243305aea7e382bec3646c2a9e33dad3f33bfb06 @mbrevoort mbrevoort committed Jul 17, 2012
Showing with 8 additions and 3 deletions.
  1. +6 −2 index.js
  2. +2 −1 package.json
View
@@ -1,5 +1,6 @@
var upnode = require('upnode');
var semver = require('semver');
+var identifier = require('identifier');
var EventEmitter = require('events').EventEmitter;
exports.connect = function () {
@@ -224,7 +225,8 @@ exports.createServer = function (opts) {
params.port = port;
params.version = version;
params.role = role;
-
+ params._id = identifier(16);
+
roles[role].push(params);
allocated.push(params);
@@ -267,6 +269,7 @@ exports.createServer = function (opts) {
params.port = port;
params.role = role;
params.version = version;
+ params._id = identifier(16);
roles[role].push(params);
allocated.push(params);
@@ -282,6 +285,7 @@ exports.createServer = function (opts) {
withAddr(function (addr) {
var port = params.port;
var host = params.host || addr;
+ var id = params._id;
if (ports[host]) {
var ix = ports[host].indexOf(port);
@@ -293,7 +297,7 @@ exports.createServer = function (opts) {
Object.keys(roles).forEach(function (role) {
var rs = roles[role];
roles[role] = rs.filter(function (r) {
- var x = r.port === port && r.host === host;
+ var x = r.port === port && r.host === host && r._id === id;
if (x) {
found = {};
Object.keys(r).forEach(function (key) {
View
@@ -29,7 +29,8 @@
"dependencies" : {
"upnode" : "~0.2.2",
"optimist" : "0.3.x",
- "semver" : "1.0.x"
+ "semver" : "1.0.x",
+ "identifier" : "0.0.x"
},
"devDependencies" : {
"tap" : "~0.2.3",

0 comments on commit 243305a

Please sign in to comment.