Skip to content

Commit

Permalink
Close and destroy sockets on connection error.
Browse files Browse the repository at this point in the history
Add `sock.end` and `sock.destroy` calls for `sock.once('error', ...)`
event handler and for `c.open(fields, ...)` callback - just like it was
done for connection timeout callback.

Resolves amqp-node#513
  • Loading branch information
Andrey Bezugliy committed May 2, 2019
1 parent 773eb92 commit 65dc6ee
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ function connect(url, socketOptions, openCallback) {
if (err === null) {
openCallback(null, c);
}
else openCallback(err);
else {
sock.end();
sock.destroy();
openCallback(err);
}
});
}

Expand All @@ -174,7 +178,11 @@ function connect(url, socketOptions, openCallback) {
}

sock.once('error', function(err) {
if (!sockok) openCallback(err);
if (!sockok) {
sock.end();
sock.destroy();
openCallback(err);
}
});

}
Expand Down

0 comments on commit 65dc6ee

Please sign in to comment.