From 9676e9c817b538154336208e6e420cc3d1df928d Mon Sep 17 00:00:00 2001 From: Seth LaForge Date: Fri, 26 Aug 2011 18:15:42 -0700 Subject: [PATCH] Minor error-handling fixes in Cursor.streamRecords. --- lib/mongodb/cursor.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/mongodb/cursor.js b/lib/mongodb/cursor.js index febf6ecea4..abbd1984ef 100644 --- a/lib/mongodb/cursor.js +++ b/lib/mongodb/cursor.js @@ -596,7 +596,11 @@ Cursor.prototype.streamRecords = function(options) { function execute(command) { self.db.executeCommand(command, {read:true}, function(err,result) { - if(err != null) return callback(err, null); + if(err) { + stream.emit('error', err); + self.close(function(){}); + return; + } if (!self.queryRun && result) { self.queryRun = true; @@ -617,9 +621,11 @@ Cursor.prototype.streamRecords = function(options) { } catch(err) { if (err != "done") { throw err; } else { - stream.emit('end', recordLimitValue); + self.close(function(){ + stream.emit('end', recordLimitValue); + }); self.close(function(){}); - return(null); + return; } } // rinse & repeat