Permalink
Browse files

connection: catch errors on upgraded tls socket

  • Loading branch information...
1 parent f7fed5a commit 2c251e6074e9541ab7397d761bb672b7564e67da @mscdex committed Oct 9, 2013
Showing with 10 additions and 4 deletions.
  1. +10 −4 lib/connection.js
View
14 lib/connection.js
@@ -251,6 +251,7 @@ FTP.prototype.connect = function(options) {
else if (cmd === 'AUTH SSL')
self._secstate = 'upgraded-ssl';
socket.removeAllListeners('data');
+ socket.removeAllListeners('error');
socket._decoder = null;
self._curReq = null; // prevent queue from being processed during
// TLS/SSL negotiation
@@ -260,6 +261,7 @@ FTP.prototype.connect = function(options) {
socket.setEncoding('binary');
socket.on('data', ondata);
socket.once('end', onend);
+ socket.once('error', onerror);
}
}
}
@@ -271,11 +273,12 @@ FTP.prototype.connect = function(options) {
self._parser.write(chunk);
}
- this._socket.once('error', function(err) {
+ socket.once('error', onerror);
+ function onerror(err) {
clearTimeout(timer);
clearTimeout(self._keepalive);
self.emit('error', err);
- });
+ }
socket.once('end', onend);
function onend() {
@@ -848,16 +851,19 @@ FTP.prototype._pasvConnect = function(ip, port, cb) {
if (self.options.secure === true) {
self.options.secureOptions.socket = socket;
self.options.secureOptions.session = self._socket.getSession();
+ //socket.removeAllListeners('error');
socket = tls.connect(self.options.secureOptions);
+ //socket.once('error', onerror);
socket.setTimeout(0);
}
clearTimeout(timer);
self._pasvSocket = socket;
cb(undefined, socket);
});
- socket.once('error', function(err) {
+ socket.once('error', onerror);
+ function onerror(err) {
sockerr = err;
- });
+ }
socket.once('end', function() {
clearTimeout(timer);
});

0 comments on commit 2c251e6

Please sign in to comment.