diff --git a/src/connection.js b/src/connection.js index 8e7c733c..eeecdbd6 100644 --- a/src/connection.js +++ b/src/connection.js @@ -32,7 +32,7 @@ class FtpConnection extends EventEmitter { this.commandSocket.on('data', this._handleData.bind(this)); this.commandSocket.on('timeout', () => { this.log.trace('Client timeout'); - this.close().catch((e) => this.log.trace(e, 'Client close error')); + this.close(); }); this.commandSocket.on('close', () => { if (this.connector) this.connector.end(); diff --git a/src/index.js b/src/index.js index 2651b67b..aae5d038 100644 --- a/src/index.js +++ b/src/index.js @@ -49,6 +49,7 @@ class FtpServer extends EventEmitter { this.connections[connection.id] = connection; socket.on('close', () => this.disconnectClient(connection.id)); + socket.once('close', () => this.emit('disconnect', {connection, id: connection.id})); const greeting = this._greeting || []; const features = this._features || 'Ready'; @@ -119,7 +120,6 @@ class FtpServer extends EventEmitter { return new Promise((resolve) => { const client = this.connections[id]; if (!client) return resolve(); - this.emit('disconnect', {connection: client, id}); delete this.connections[id]; try { client.close(0);