Skip to content
This repository has been archived by the owner on Apr 21, 2020. It is now read-only.

Commit

Permalink
Fix a race condition with key deletion.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanbreen committed Dec 12, 2014
1 parent c9ba687 commit 3345ba7
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/proxy/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ function ProxyKeys(config) {
ProxyKeys.prototype.load = function(cb) {
var this_obj = this;

// Keep track of the keys that were registered as of now so that we can compare against
// the list we're about to load. Anything that remains in delete_me should be, like, deleted.
var delete_me = {};

_.each(this_obj, function(value, key) {
delete this_obj[key];
delete_me[key] = true;
});

var key_count = 0;
Expand Down Expand Up @@ -70,6 +74,8 @@ ProxyKeys.prototype.load = function(cb) {
// of the current object. These properties are enumerable and configurable, so future runs
// of the load command will be able to delete and re-add these properties as necessary.
Object.defineProperty(this_obj, file_name, { value: encoding.encodeData(file_contents), configurable: true, enumerable: true });
// We don't want to delete this property, so delete it from delete_me.
delete delete_me[file_name];

// Increment the key count
++key_count;
Expand All @@ -86,6 +92,11 @@ ProxyKeys.prototype.load = function(cb) {
}
});

for (var key_to_delete in delete_me) {
logger.info("Deleting key %s", key_to_delete);
delete this_obj[key_to_delete];
}

// Set the count property of this object.
this_obj.count = key_count;

Expand Down

0 comments on commit 3345ba7

Please sign in to comment.