Skip to content

Commit

Permalink
Fixed memory leak issue caused by not recognizing undefined correctly…
Browse files Browse the repository at this point in the history
… as a value in _events, Issue #1059
  • Loading branch information
christkv committed Aug 10, 2013
1 parent 097fbaa commit 8a31908
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
5 changes: 5 additions & 0 deletions HISTORY
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
1.3.18 2013-08-10
-----------------
- Fixed issue when throwing exceptions in MongoClient.connect/Db.open (Issue #1057)
- Fixed an issue where _events is not cleaned up correctly causing a slow steady memory leak.

1.3.17 2013-08-07
-----------------
- Ignore return commands that have no registered callback
Expand Down
2 changes: 1 addition & 1 deletion docs/sphinx-docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
# The short X.Y version.
version = '1.3'
# The full version, including alpha/beta/rc tags.
release = '1.3.17'
release = '1.3.18'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
19 changes: 12 additions & 7 deletions lib/mongodb/connection/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,9 @@ Base.prototype.__executeAllCallbacksWithError = function(err) {
// Remove the key
delete this._callBackStore._notReplied[keys[j]];
// Force cleanup _events, node.js seems to set it as a null value
if(this._callBackStore._events != null
&& this._callBackStore._events[keys[j]] != null) delete this._callBackStore._events[keys[j]];
if(this._callBackStore._events) {
delete this._callBackStore._events[keys[j]];
}
}
}

Expand All @@ -315,8 +316,9 @@ Base.prototype.__executeAllServerSpecificErrorCallbacks = function(host, port, e
// Remove the key
delete this._callBackStore._notReplied[keys[j]];
// Force cleanup _events, node.js seems to set it as a null value
if(this._callBackStore._events != null
&& this._callBackStore._events[keys[j]] != null) delete this._callBackStore._events[keys[j]];
if(this._callBackStore._events) {
delete this._callBackStore._events[keys[j]];
}
}
}
}
Expand Down Expand Up @@ -371,7 +373,9 @@ Base.prototype._callHandler = function(id, document, err) {
// Remove the listeners
this._callBackStore.removeAllListeners(id);
// Force key deletion because it nulling it not deleting in 0.10.X
if(this._callBackStore._events && this._callBackStore._events[id] != null) delete this._callBackStore._events[id];
if(this._callBackStore._events) {
delete this._callBackStore._events[id];
}

try {
// Execute the callback if one was provided
Expand Down Expand Up @@ -402,8 +406,9 @@ Base.prototype._removeHandler = function(id) {
// Remove the callback if it's registered
this._callBackStore.removeAllListeners(id);
// Force cleanup _events, node.js seems to set it as a null value
if(this._callBackStore._events != null
&& this._callBackStore._events[id] != null) delete this._callBackStore._events[id];
if(this._callBackStore._events) {
delete this._callBackStore._events[id];
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ "name" : "mongodb"
, "description" : "A node.js driver for MongoDB"
, "keywords" : ["mongodb", "mongo", "driver", "db"]
, "version" : "1.3.17"
, "version" : "1.3.18"
, "author" : "Christian Amor Kvalheim <christkv@gmail.com>"
, "contributors" : [ "Aaron Heckmann",
"Christoph Pojer",
Expand Down
6 changes: 4 additions & 2 deletions test/tests/manual_tests/load_testing_end_point.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ var http = require('http'),

console.log('launching simple mongo application...');
// var url = "mongodb://localhost:30000,localhost:30001,localhost:30002/foo&readPreference=secondaryPreferred"
var url = "mongodb://192.168.2.173:30000,192.168.2.173:30001,192.168.2.173:30002/foo&readPreference=secondaryPreferred";
var writeOptions = {w:3};
// var url = "mongodb://192.168.2.173:30000,192.168.2.173:30001,192.168.2.173:30002/foo&readPreference=secondaryPreferred";
var url = "mongodb://localhost:27017/test"
// var writeOptions = {w:3};
var writeOptions = {w:1};

// Connect
MongoClient.connect(url, function(err, db) {
Expand Down

0 comments on commit 8a31908

Please sign in to comment.