Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Object #<CleartextStream> has no method 'unref' #299

Open
bendytree opened this issue Apr 6, 2016 · 1 comment
Open

Error Object #<CleartextStream> has no method 'unref' #299

bendytree opened this issue Apr 6, 2016 · 1 comment

Comments

@bendytree
Copy link
Contributor

node: 0.10.26
mongojs: 2.3.0
mongodb-core: 1.3.13
MongoDB database: v3.2.1
Web host: heroku

I'm using mongojs to connect to a db:

var connectionString = "mongodb://username:password@aws-us-east-1-portal.4.dblayer.com:00000,aws-us-east-1-portal.3.dblayer.com:00000/dbname?ssl=true";
var options = {
    "mongos": {
      "ssl": true,
      "sslValidate": false
    }
};
var db = mongojs(connectionString, [...], options);

I recently updated from mongojs 0.14.2 and now I sometimes get this error from the connection:

Object #<CleartextStream> has no method 'unref' 
TypeError: Object #<CleartextStream> has no method 'unref' 
    at Connection.destroy (/app/node_modules/mongojs/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:441:21) 
    at /app/node_modules/mongojs/node_modules/mongodb/node_modules/mongodb-core/lib/connection/pool.js:189:7 
    at Array.forEach (native) 
    at Pool.destroy (/app/node_modules/mongojs/node_modules/mongodb/node_modules/mongodb-core/lib/connection/pool.js:182:15) 
    at Server.destroy (/app/node_modules/mongojs/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:1040:31) 
    at Server.close (/app/node_modules/mongojs/node_modules/mongodb/lib/server.js:398:17) 
    at Db.close (/app/node_modules/mongojs/node_modules/mongodb/lib/db.js:357:19) 
    at /app/node_modules/mongojs/node_modules/mongodb/lib/mongo_client.js:312:14 
    at /app/node_modules/mongojs/node_modules/mongodb/lib/db.js:234:5 
    at connectHandler (/app/node_modules/mongojs/node_modules/mongodb/lib/server.js:306:7) 
    at g (events.js:180:16) 
    at EventEmitter.emit (events.js:95:17) 
    at /app/node_modules/mongojs/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:540:23 
    at commandCallback (/app/node_modules/mongojs/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:1161:9) 
    at Callbacks.emit (/app/node_modules/mongojs/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:119:3) 
    at null.messageHandler (/app/node_modules/mongojs/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:295:23) 

It appears to be an issue with the mongodb-core library.

Line 441 is actually commented out, but there is a nearby call to connection.unref() so I'm guessing that's the issue.

It looks like tls.TLSSocket replaced CleartextStream in node v0.10.40.

I'm guessing connection.unref() expects node 0.10.40 or higher.

So mongojs only supports 0.10.40 or higher - does that sound right?

@bendytree
Copy link
Contributor Author

I filed an issue with mongodb-core and they said mongodb-core 1.3+ requires node 0.12.x or higher.

So looking through mongojs dependencies, mongojs 1.0.1 is the last version that can be used with node 0.10.x.

Here's the actual response from mongodb-core:

mongodb-core 1.3 and higher does not attempt to support node 0.10.x beyond best effort. Socket.unref is unsupported on 0.10.x unfortunately but used in mongodb-core. I would suggest one of three things.
1. Upgrade node to 0.12.x or higher.
2. Open a mongojs ticket asking them to mock out the unref method on the Socket prototype so it becomes a no-op
3. Just mock out the unref method yourself and turn it into a no-op.
  var Socket = require('net').Socket;
  Socket.prototype.unref = function() {};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant