askmike / bitstamp

Bitstamp REST API wrapper
80 stars 54 forks source link

Catch socket timeout error #14

Closed Removed-5an closed 10 years ago

Removed-5an commented 10 years ago

Needs to be verified if this actually catches the error and if it doesn't cause double callbacks.

askmike commented 10 years ago

I can remember that an error is triggered for both the socket as the req after a timeout, which would cause the cb to run twice. I need to test this first.

Removed-5an commented 10 years ago

Agreed, I'm not sure on how you can "fake/replicate" a timeout, so I didn't try it out myself.

askmike commented 10 years ago

What I usually do is set the timeout to something like 10ms so that it is always triggered (my internet is not that quick). I can also do this soon myself.

On Tue, Mar 11, 2014 at 3:49 PM, 5an1ty notifications@github.com wrote:

Agreed, I'm not sure on how you can "fake/replicate" a timeout, so I didn't try it out myself.

Reply to this email directly or view it on GitHubhttps://github.com/askmike/bitstamp/pull/14#issuecomment-37303805 .

Removed-5an commented 10 years ago

Oh that's smart! If you don't find the time, I'll try it out myself later on.

Removed-5an commented 10 years ago

Hmm, when I try a low setTimeout I get the following error:

{ [Error: socket hang up] code: 'ECONNRESET' }

Not the same error that I had before: Error: connect ETIMEDOUT at errnoException (net.js:904:11) at Object.afterConnect as oncomplete

Removed-5an commented 10 years ago

However adding:

socket.on('error', function(err){
  callback(err);
});

Doesn't cause for a double callback, so we might as well have it in.

askmike commented 10 years ago

awesome thanks!