Skip to content

Commit

Permalink
Cherry pick door fix
Browse files Browse the repository at this point in the history
  • Loading branch information
NuSkooler committed Feb 6, 2024
1 parent f638ea8 commit 69710d4
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions core/door.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,42 @@ module.exports = class Door {
'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) {
this.client.log.debug('Using stdio for door I/O');

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*/) => {
return this.restoreIo(this.doorPty);
});
this.doorPty.onData(this.doorDataHandler.bind(this));
} else if ('socket' === this.io) {
this.client.log.debug(
{
Expand All @@ -184,20 +210,7 @@ module.exports = class Door {
this.doorPty.onExit(exitEvent => {
const {exitCode, signal} = exitEvent;
this.client.log.info({ exitCode, signal }, 'Door exited');

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);
exitHandler();
});
},
],
Expand Down

0 comments on commit 69710d4

Please sign in to comment.