{"issue":{"state":"open","created_at":"2011-12-15T10:57:51Z","updated_at":"2011-12-15T11:11:39Z","user":{"gravatar_id":"d1bf2ff368596018547b521e94211dbe","id":1254892,"url":"https://api.github.com/users/d1april","avatar_url":"https://secure.gravatar.com/avatar/d1bf2ff368596018547b521e94211dbe?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"d1april"},"comments":1,"body":"I had the problem with cursor.streamRecords that it streamed an infinite amount of documents or until the given limit was reached.\r\nThis happened only with an connection to mongos, while a connection to mongod was fine.\r\n\r\nAfter the documents I supposed to get were received I got an infinite amount of those error documents: \r\n{ '$err': 'assertion s/cursors.cpp:179', code: 0 }\r\n\r\nTo debug it I added this this to the cursor.js Cursor.prototype.streamRecords:\r\n\r\n```\r\nfunction execute(command) {\r\n    self.db._executeQueryCommand(command, {read:true, raw:self.raw}, function(err,result) {\r\n\t    console.log('cursor result: '+err+' '+require('util').inspect(result,false,2));\r\n```\r\n\r\nThis was the output:\r\n```\r\ncursor result: null { documents: [ all fine documents ],\r\n  index: 521134,\r\n  messageLength: 521134,\r\n  requestId: 852709,\r\n  responseTo: 5,\r\n  responseFlag: 8,\r\n  cursorId: 0,\r\n  startingFrom: 0,\r\n  numberReturned: 75 }\r\ncursor result: null { documents: [ { '$err': 'assertion s/cursors.cpp:179', code: 0 } ],\r\n  index: 89,\r\n  messageLength: 89,\r\n  requestId: 852743,\r\n  responseTo: 6,\r\n  responseFlag: 2,\r\n  cursorId: 0,\r\n  startingFrom: 0,\r\n  numberReturned: 1 }\r\n```\r\n\r\nI looked up what the responseFlag means: http://www.mongodb.org/display/DOCS/Mongo+Wire+Protocol#MongoWireProtocol-OPREPLY\r\n1 \t QueryFailure \t Set when query failed. Results consist of one document containing an \"$err\" field describing the failure.\r\n\r\n\r\nThis is how I fixed it:\r\nReplace: \r\n```\r\nif (result.documents && result.documents.length) {\r\n```\r\nWith:\r\n```\r\n\t  var resflagsMap={\r\n\t\t  CursorNotFound:1<<0,\r\n\t\t  QueryFailure:1<<1,\r\n\t\t  ShardConfigStale:1<<2,\r\n\t\t  AwaitCapable:1<<3\r\n\t  };\r\n      if (result.documents && result.documents.length && !(result.responseFlag&resflagsMap.QueryFailure)) {\r\n ```\r\n\r\nI hope it helps.","assignee":null,"id":2565330,"number":442,"pull_request":{"patch_url":null,"html_url":null,"diff_url":null},"labels":[],"title":"infinite streamRecords QueryFailure fix","html_url":"https://github.com/christkv/node-mongodb-native/issues/442","closed_at":null,"milestone":null,"url":"https://api.github.com/repos/christkv/node-mongodb-native/issues/442"},"action":"created","comment":{"created_at":"2011-12-15T11:11:38Z","updated_at":"2011-12-15T11:11:38Z","user":{"gravatar_id":"a132807512f576d8b2394a7a8b0379a0","id":5569,"url":"https://api.github.com/users/christkv","avatar_url":"https://secure.gravatar.com/avatar/a132807512f576d8b2394a7a8b0379a0?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"christkv"},"body":"can you have a try with the latest npm version 0.9.7.2 that I released","id":3159738,"url":"https://api.github.com/repos/christkv/node-mongodb-native/issues/comments/3159738"}}