Skip to content

Commit

Permalink
Node socket.removeAllListeners() without name doesn't work
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickjuchli committed Jun 5, 2018
1 parent 5e60537 commit 70d92cd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions lib/FtpContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ module.exports = class FTPContext {
// No data socket should be open in any case where the control socket is set or upgraded.
this.dataSocket = undefined;
if (this._socket) {
this._socket.removeAllListeners();
// socket.removeAllListeners() without name doesn't work: https://github.com/nodejs/node/issues/20923
this._socket.removeAllListeners("timeout");
this._socket.removeAllListeners("data");
this._socket.removeAllListeners("error");
}
if (socket) {
socket.setKeepAlive(true);
Expand Down Expand Up @@ -206,7 +209,10 @@ module.exports = class FTPContext {
_closeSocket(socket) {
if (socket) {
socket.destroy();
socket.removeAllListeners();
// socket.removeAllListeners() without name doesn't work: https://github.com/nodejs/node/issues/20923
socket.removeAllListeners("timeout");
socket.removeAllListeners("data");
socket.removeAllListeners("error");
}
}
};
4 changes: 2 additions & 2 deletions lib/ftp.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,8 @@ function upgradeSocket(socket, options) {
reject(tlsSocket.authorizationError);
}
else {
// Remove any listeners we set up here, e.g. error listener below.
tlsSocket.removeAllListeners();
// Remove error listener below.
tlsSocket.removeAllListeners("error");
resolve(tlsSocket);
}
}).once("error", error => {
Expand Down

0 comments on commit 70d92cd

Please sign in to comment.