Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

emit 'error' on `this` upon 'ECONNREFUSED' #77

Closed
wants to merge 1 commit into from

2 participants

@guybrush

this will not work, since the connection never gets established

// nothing is listening on 4444
dnode.connect(4444,{reconnect:100},function(remote,conn){
  conn.on('refused',function(){console.log('refused')})
})

in fact the 'refused' event will never be emitted, since attachDnode() will not be called because there wont be a stream-event 'connect' - right?

so i thought it would be best to this.emit('error',err)?

note: the readme would have to be updated too

@substack substack closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 2, 2011
  1. @guybrush
This page is out of date. Refresh to see the latest.
Showing with 18 additions and 1 deletion.
  1. +1 −1  index.js
  2. +17 −0 test/error.js
View
2  index.js 100644 → 100755
@@ -63,7 +63,7 @@ dnode.prototype.connect = function () {
if (params.reconnect) {
stream.on('error', (function (err) {
if (err.code === 'ECONNREFUSED') {
- if (client) client.emit('refused');
+ this.emit('error', err);
setTimeout((function () {
if (client) client.emit('reconnect');
View
17 test/error.js 100644 → 100755
@@ -85,3 +85,20 @@ test('refused', function (t) {
t.end();
});
});
+
+test('refused with reconnect-option', function (t) {
+ t.plan(2);
+
+ var port = Math.floor(Math.random() * 40000 + 10000);
+ var client = dnode.connect(port, {reconnect:100}, function (remote, conn) {
+ assert.fail('should have been refused, very unlikely');
+ });
+
+ client.on('error', function (err) {
+ t.equal(err.code, 'ECONNREFUSED');
+ t.equal(err.syscall, 'connect');
+ client.destroy();
+ t.end();
+ });
+});
+
Something went wrong with that request. Please try again.