On Fri, Feb 10, 2012 at 20:50, Geoff Flarity <[email protected]> wrote:
> Hi!
>
> I'm not sure if this expected behaviour or not. I'm trying to create
> socket connection that automatically reconnects if something bad
> happens.
>
> https://github.com/gflarity/nervous/blob/master/lib/graphite_axon.js#L60
>
> When a socket emits an 'error' event, I destroy the connection. When
> the 'close' event happens I reconnect. Most of the time this works but
> it doesn't seem to work with ENOTFOUND errors.
>
>  This sort of makes sense to me. The dns lookup fails so node doesn't
> even try to create a connection. If the connection doesn't even get
> attempted, then there's no reason to emit a 'close' event on that
> connection.  But then how do I code around this?

I suspect that you're running into a subtle bug. Can you try this patch?

diff --git a/lib/net.js b/lib/net.js
index f98bcfc..64c4dfd 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -569,8 +569,7 @@ Socket.prototype.connect = function(port /*
[host], [cb] */) {
         // There are no event listeners registered yet so defer the
         // error event to the next tick.
         process.nextTick(function() {
-          self.emit('error', err);
-          self.destroy();
+          self.destroy(err);
         });
       } else {
         timers.active(self);

[1] https://gist.github.com/1792505

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to