Bug fix: If user disconnects, don't leave a haning door PID
This commit is contained in:
parent
37653545f3
commit
a2f1e28894
17
core/door.js
17
core/door.js
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue