Permalink
Browse files

Fix an infinite loop on connection error (this fixes issue #3)

Sometimes, an error happens on the socket, but the 'close' event is called
with "had_errors" set to False.  In this case, we would could ourselves
recursively *twice*, which leads to an exponential number of recursive
calls over time.

This happens, for instance, when DNS resolution fails.

According to the doc, we only need to handle the 'close' event:

  http://nodejs.org/api/net.html#net_event_error_1
  • Loading branch information...
1 parent 53e93b2 commit c1867eb2271a4c56186a119600e6e74600d39911 Baptiste Jonglez committed Jun 23, 2014
Showing with 4 additions and 6 deletions.
  1. +4 −6 babelNode.js
View
@@ -116,7 +116,6 @@
if(typeof state.self.id !== "undefined") {
closeCallback(node, state.self.id);
}
- if (error) { return; /* already handled */ }
if(!connectionFailure) {
log("error", "Babel socket close: reconnecting in 1 second.");
}
@@ -125,11 +124,10 @@
});
client.on('error', function () {
- if(!connectionFailure) {
- log("error", "Babel socket close: reconnecting in 1 second.");
- }
- connectionFailure = true;
- setTimeout(babelConnect, 1000);
+ /* Do nothing, 'close' will be called in any case.
+ * http://nodejs.org/api/net.html#net_event_error_1
+ */
+ return;
});
}

0 comments on commit c1867eb

Please sign in to comment.