clearbit / clearbit-node

Node library for querying the Clearbit business intelligence APIs
https://clearbit.com/docs
MIT License
69 stars 35 forks source link

ECONNRESET on Person.find #3

Closed jonDowdle closed 9 years ago

jonDowdle commented 9 years ago

When trying to find a person, I get a connection issue.

Failing test case:

var clearbit = require('clearbit')('KEY_REDACTED');

clearbit.Person.find({email: 'alex@alexmaccaw.com'})
  .then(function (person) {
    console.log('Name: ', person.name.fullName);
  })
  .catch(clearbit.Person.QueuedError, function (err) {
    // Lookup is queued - try again later
    console.log(err);
  })
  .catch(clearbit.Person.NotFoundError, function (err) {
    // Person could not be found
    console.log(err);
  })
  .catch(function (err) {
    console.error(err);
  });

and the error

{ name: 'OperationalError',
  message: 'socket hang up',
  cause: { [Error: socket hang up] code: 'ECONNRESET' },
  stack: 'Error: socket hang up\n    at createHangUpError (http.js:1472:15)\n    at CleartextStream.socketCloseListener (http.js:1522:23)\n    at CleartextStream.EventEmitter.emit (events.js:117:20)\n    at tls.js:696:10\n    at process._tickCallback (node.js:415:13)' }

but when I just connect using tls.connect() (or request even) - it works.

require('tls').connect(443, 'person.clearbit.com', function() {
  this.write('GET /v1/people/email/alex@alexmaccaw.com HTTP/1.1\r\nAuthorization: Basic REDACTED\r\nHost: person.clearbit.com\r\n\r\n');
  this.pipe(process.stdout);
});

Some details on my system:

Here is a gist of with my Vagrantfile if you'd like to test in the exact same circumstances. https://gist.github.com/jonDowdle/91c930cc3bb6a324676e

maccman commented 9 years ago

Golly this is an odd one - let me do a bit more digging.

jonDowdle commented 9 years ago

Sure thing. Let me know if I can help at all - I'd love to use the library vs just using request.

jonDowdle commented 9 years ago

@maccman I took a look at this today and it looks like the connection timeout (set with needle) might be to a clue into what is happening.

Here's the script I used to test and here is the output. It always succeeds with a timeout of 5400.

ERROR with timeout 5000: {"code":"ECONNRESET"}
ERROR with timeout 5100: {"code":"ECONNRESET"}
ERROR with timeout 5200: {"code":"ECONNRESET"}
ERROR with timeout 5300: {"code":"ECONNRESET"}
Success with timeout 5400
Status code 200

In testing a few other sites, (SSL and not) they all seem to have issues with a timeout of 5000. Increasing the timeout just a little bit (5200-5400) does succeed though.

bendrucker commented 9 years ago

Not sure how specific this is to your setup. Why not just bump the timeout to 10000 across the board instead of adding another config option to document?

jonDowdle commented 9 years ago

Works for me.