{"issue":{"state":"open","created_at":"2011-11-23T14:05:20Z","updated_at":"2011-11-24T19:11:37Z","comments":12,"user":{"gravatar_id":"ad418e3e53e0ba71ba56b7df978671e8","id":33538,"url":"https://api.github.com/users/novemberborn","login":"novemberborn","avatar_url":"https://secure.gravatar.com/avatar/ad418e3e53e0ba71ba56b7df978671e8?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"body":"Running the test script below. It gets stuck at \"querying all users\" for a while and then crashes with this error:\r\n\r\n```\r\nbuffer.js:374\r\n  if (end > this.length) throw new Error('oob');\r\n                               ^\r\nError: oob\r\n    at Buffer.slice (buffer.js:374:32)\r\n    at Socket.<anonymous> (…/node_modules/mongodb/lib/mongodb/connection/connection.js:253:41)\r\n    at Socket.emit (events.js:64:17)\r\n    at Socket._onReadable (net.js:678:14)\r\n    at IOWatcher.onReadable [as callback] (net.js:177:10)\r\n```\r\n\r\n```js\r\nvar mongodb = require(\"mongodb\");\r\n\r\nvar options = {\r\n  auto_reconnect: true,\r\n  poolSize: 4,\r\n  socketOptions: { keepAlive: 100 }\r\n};\r\nvar replSet = new mongodb.ReplSetServers([\r\n  new mongodb.Server(\"mongo-1\", 27017, options),\r\n  new mongodb.Server(\"mongo-2\", 27017, options),\r\n  new mongodb.Server(\"mongo-3\", 27017, options)\r\n]);\r\nvar db = new mongodb.Db(\"data\", replSet);\r\ndb.open(function(err, client){\r\n  client.collection(\"users\", function(err, users){\r\n    console.log(\"Connected\");\r\n    db.users = users;\r\n    query();\r\n  });\r\n});\r\n\r\nfunction query(){\r\n  console.log(\"[%s] querying all users\", new Date);\r\n  setTimeout(query, 70 * 60 * 1000);\r\n  db.users.find().count(function(err, all){\r\n    if(err){\r\n      console.log(\"[%s] %s\", new Date, err.stack || err);\r\n    }else{\r\n      console.log(\"[%s] found %s users\", new Date, all);\r\n    }\r\n  });\r\n}\r\n```","assignee":null,"id":2329860,"number":414,"labels":[],"pull_request":{"patch_url":null,"html_url":null,"diff_url":null},"title":"Buffer OOB in 0.9.7.1-dev","html_url":"https://github.com/christkv/node-mongodb-native/issues/414","closed_at":null,"milestone":null,"url":"https://api.github.com/repos/christkv/node-mongodb-native/issues/414"},"action":"created","comment":{"created_at":"2011-11-24T19:11:37Z","updated_at":"2011-11-24T19:11:37Z","user":{"gravatar_id":"a132807512f576d8b2394a7a8b0379a0","id":5569,"url":"https://api.github.com/users/christkv","login":"christkv","avatar_url":"https://secure.gravatar.com/avatar/a132807512f576d8b2394a7a8b0379a0?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"body":"try\r\n\r\ntimeout:30000 as well as KeepAlive or maybe even less\r\n\r\nthe timeout will timeout the socket if there is no activity (meaning keepAlive is not getting replies). This will cause the socket to error out correctly. You can experiment with the timeout. For my test I put 30 seconds but you might want something a little bit shorter (depends on your need)\r\n\r\nCheers\r\n\r\nChristian\r\n\r\n\r\n\r\nOn Nov 24, 2011, at 7:50 PM, Mark Wubben wrote:\r\n\r\n> CPU problem repeated itself. This is on our Rackspace server, some Linux distro.\r\n> \r\n> --- \r\n> Reply to this email directly or view it on GitHub:\r\n> https://github.com/christkv/node-mongodb-native/issues/414#issuecomment-2868203","id":2868356,"url":"https://api.github.com/repos/christkv/node-mongodb-native/issues/comments/2868356"}}