Bug fix: If user disconnects, don't leave a haning door PID

This commit is contained in:
Bryan Ashby 2020-10-15 20:54:55 -06:00
parent 37653545f3
commit a2f1e28894
No known key found for this signature in database
GPG Key ID: B49EB437951D2542
1 changed files with 16 additions and 1 deletions

View File

@ -3,12 +3,14 @@
const stringFormat = require('./string_format.js');
const { Errors } = require('./enig_error.js');
const Events = require('./events');
// deps
const pty = require('node-pty');
const decode = require('iconv-lite').decode;
const createServer = require('net').createServer;
const paths = require('path');
const _ = require('lodash');
module.exports = class Door {
constructor(client) {
@ -87,6 +89,19 @@ module.exports = class Door {
return cb(e);
}
//
// PID is launched. Make sure it's killed off if the user disconnects.
//
Events.once(Events.getSystemEvents().ClientDisconnected, evt => {
if (this.doorPty && this.client.session.uniqueId === _.get(evt, 'client.session.uniqueId')) {
this.client.log.info(
{ pid : this.doorPty.pid },
'User has disconnected; Killing door process.'
);
this.doorPty.kill();
}
});
this.client.log.debug(
{ processId : this.doorPty.pid }, 'External door process spawned'
);
@ -96,7 +111,7 @@ module.exports = class Door {
this.client.term.output.pipe(this.doorPty);
this.doorPty.on('data', this.doorDataHandler.bind(this));
this.doorPty.onData(this.doorDataHandler.bind(this));
this.doorPty.once('close', () => {
return this.restoreIo(this.doorPty);