Cherry pick door fix
This commit is contained in:
49
core/door.js
49
core/door.js
@@ -161,16 +161,42 @@ module.exports = class Door {
|
|||||||
'External door process spawned'
|
'External door process spawned'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const exitHandler = () => {
|
||||||
|
if (this.sockServer) {
|
||||||
|
this.sockServer.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// we may not get a close
|
||||||
|
if ('stdio' === this.io) {
|
||||||
|
this.restoreIo(this.doorPty);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.doorPty) {
|
||||||
|
this.doorPty.removeAllListeners();
|
||||||
|
delete this.doorPty;
|
||||||
|
}
|
||||||
|
|
||||||
|
return callback(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.doorPty.on('error', err => {
|
||||||
|
this.client.log.warn(
|
||||||
|
{ error: err.message },
|
||||||
|
'Door exited with error'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
if ('stdio' === this.io) {
|
if ('stdio' === this.io) {
|
||||||
this.client.log.debug('Using stdio for door I/O');
|
this.client.log.debug('Using stdio for door I/O');
|
||||||
|
|
||||||
this.client.term.output.pipe(this.doorPty);
|
this.client.term.output.pipe(this.doorPty);
|
||||||
|
|
||||||
this.doorPty.onData(this.doorDataHandler.bind(this));
|
// dumb hack around node-pty; under nix, if we bail at the
|
||||||
|
// right time, listenerCount will be referenced, but does
|
||||||
|
// not exist!
|
||||||
|
this.doorPty.listenerCount = () => 1;
|
||||||
|
|
||||||
this.doorPty.onExit( (/*exitEvent*/) => {
|
this.doorPty.onData(this.doorDataHandler.bind(this));
|
||||||
return this.restoreIo(this.doorPty);
|
|
||||||
});
|
|
||||||
} else if ('socket' === this.io) {
|
} else if ('socket' === this.io) {
|
||||||
this.client.log.debug(
|
this.client.log.debug(
|
||||||
{
|
{
|
||||||
@@ -184,20 +210,7 @@ module.exports = class Door {
|
|||||||
this.doorPty.onExit(exitEvent => {
|
this.doorPty.onExit(exitEvent => {
|
||||||
const {exitCode, signal} = exitEvent;
|
const {exitCode, signal} = exitEvent;
|
||||||
this.client.log.info({ exitCode, signal }, 'Door exited');
|
this.client.log.info({ exitCode, signal }, 'Door exited');
|
||||||
|
exitHandler();
|
||||||
if (this.sockServer) {
|
|
||||||
this.sockServer.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
// we may not get a close
|
|
||||||
if ('stdio' === this.io) {
|
|
||||||
this.restoreIo(this.doorPty);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.doorPty.removeAllListeners();
|
|
||||||
delete this.doorPty;
|
|
||||||
|
|
||||||
return callback(null);
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user