{"action":"created","issue":{"url":"https://api.github.com/repos/christkv/mongodb-core/issues/77","repository_url":"https://api.github.com/repos/christkv/mongodb-core","labels_url":"https://api.github.com/repos/christkv/mongodb-core/issues/77/labels{/name}","comments_url":"https://api.github.com/repos/christkv/mongodb-core/issues/77/comments","events_url":"https://api.github.com/repos/christkv/mongodb-core/issues/77/events","html_url":"https://github.com/christkv/mongodb-core/issues/77","id":135944904,"number":77,"title":"Cursor's memory leak!","user":{"login":"zensh","id":863754,"avatar_url":"https://avatars.githubusercontent.com/u/863754?v=3","gravatar_id":"","url":"https://api.github.com/users/zensh","html_url":"https://github.com/zensh","followers_url":"https://api.github.com/users/zensh/followers","following_url":"https://api.github.com/users/zensh/following{/other_user}","gists_url":"https://api.github.com/users/zensh/gists{/gist_id}","starred_url":"https://api.github.com/users/zensh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zensh/subscriptions","organizations_url":"https://api.github.com/users/zensh/orgs","repos_url":"https://api.github.com/users/zensh/repos","events_url":"https://api.github.com/users/zensh/events{/privacy}","received_events_url":"https://api.github.com/users/zensh/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2016-02-24T03:44:17Z","updated_at":"2016-02-24T08:01:45Z","closed_at":"2016-02-24T07:16:17Z","body":"http://stackoverflow.com/questions/27392679/memory-leaks-when-iterating-over-mongo-data-stream-using-nodejs\r\n\r\nConsumed documents in `cursor.cursorState.documents` will not be removed!\r\n\r\nDemo code:\r\n```js\r\nthunk(function *() {\r\n  yield [mongo.clientReady, mongo.oplogClientReady]\r\n  yield thunk.delay(100)\r\n\r\n  let oplog = mongo.oplogClient.db.collection('oplog.rs')\r\n  let cursor = oplog.find()\r\n    .addCursorFlag('tailable', true)\r\n    .addCursorFlag('noCursorTimeout', true)\r\n    .addCursorFlag('awaitData', true)\r\n    .addCursorFlag('exhaust', true)\r\n\r\n  let count = 0\r\n  while (true) {\r\n    let log = yield cursor.next()\r\n    console.log(count++, log.ns, log.ts, cursor.cursorState.documents.length)\r\n  }\r\n})(ilog.error)\r\n```\r\n\r\nResult:\r\n```sh\r\n528018 'talksync.messages' Timestamp { _bsontype: 'Timestamp', low_: 9065, high_: 1456264568 } 528020\r\n528019 'talksync.messages' Timestamp { _bsontype: 'Timestamp', low_: 9066, high_: 1456264568 } 528020\r\n\r\n<--- Last few GCs --->\r\n\r\n  202118 ms: Scavenge 1401.6 (1457.9) -> 1401.6 (1457.9) MB, 5.5 / 0 ms (+ 2.7 ms in 1 steps since last GC) [allocation failure] [incremental marking delaying mark-sweep].\r\n  203039 ms: Mark-sweep 1401.6 (1457.9) -> 1401.5 (1457.9) MB, 920.3 / 0 ms (+ 4.0 ms in 2 steps since start of marking, biggest step 2.7 ms) [last resort gc].\r\n  203957 ms: Mark-sweep 1401.5 (1457.9) -> 1401.2 (1457.9) MB, 918.7 / 0 ms [last resort gc].\r\n\r\n\r\n<--- JS stacktrace --->\r\n\r\n==== JS stack trace =========================================\r\n\r\nSecurity context: 0x3fab912b4629 <JS Object>\r\n    1: /* anonymous */(aka /* anonymous */) [/Users/zensh/git/teambition/databus/node_modules/mongoose/node_modules/bson/lib/bson/parser/deserializer.js:~37] [pc=0x1e082ac08460] (this=0x3fab912041b9 <undefined>,buffer=0x3fab912885b9 <an Uint8Array with map 0xd5818104d09>,index=73,options=0x3fab91288609 <an Object with map 0xd58181bb2c9>,isArray=0x3fab91204251 <false>)\r\n    2: /* anonymous */(aka...\r\n\r\nFATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory\r\n[1]    3511 abort      node\r\n```"},"comment":{"url":"https://api.github.com/repos/christkv/mongodb-core/issues/comments/188131917","html_url":"https://github.com/christkv/mongodb-core/issues/77#issuecomment-188131917","issue_url":"https://api.github.com/repos/christkv/mongodb-core/issues/77","id":188131917,"user":{"login":"eshujiushiwo","id":9065777,"avatar_url":"https://avatars.githubusercontent.com/u/9065777?v=3","gravatar_id":"","url":"https://api.github.com/users/eshujiushiwo","html_url":"https://github.com/eshujiushiwo","followers_url":"https://api.github.com/users/eshujiushiwo/followers","following_url":"https://api.github.com/users/eshujiushiwo/following{/other_user}","gists_url":"https://api.github.com/users/eshujiushiwo/gists{/gist_id}","starred_url":"https://api.github.com/users/eshujiushiwo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eshujiushiwo/subscriptions","organizations_url":"https://api.github.com/users/eshujiushiwo/orgs","repos_url":"https://api.github.com/users/eshujiushiwo/repos","events_url":"https://api.github.com/users/eshujiushiwo/events{/privacy}","received_events_url":"https://api.github.com/users/eshujiushiwo/received_events","type":"User","site_admin":false},"created_at":"2016-02-24T08:01:45Z","updated_at":"2016-02-24T08:01:45Z","body":"HI @christkv \r\n\bThanks for the reply.\r\nI have a question about this case.\r\n When using tailable cursor , we wanna trace and monitor the change of this collection.\r\nOnce there is no data writing into the collection,the cursor should waiting for the new data.\r\nAnd  MongoDB will not kill the cursor , will driver kill the cursor itself?\r\nwhen using tailable cursor with php or golang, it might wait for the new data.\r\n\r\nThanks for ur help.\r\n"}}