Skip to content

Commit

Permalink
fix: emit disconnect event on client close
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Stewart committed Jul 20, 2020
1 parent fdf5c49 commit bad051a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit bad051a

Please # to comment.