Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,7 @@ class Channel extends DuplexStream {
throw new Error('Client-only method called in server mode');

if (this.type === 'session'
&& this.writable
&& this.outgoing.state === 'open') {
&& (this.outgoing.state === 'open' || this.outgoing.state === 'eof')) {
this._client._protocol.signal(this.outgoing.id, signalName);
}
}
Expand Down
35 changes: 35 additions & 0 deletions test/test-exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,41 @@ const setup = setupSimple.bind(undefined, DEBUG);
}));
}

{
const { client, server } = setup('Exec with signal() after EOF');

const COMMAND = 'foo --bar';

server.on('connection', mustCall((conn) => {
conn.on('ready', mustCall(() => {
conn.on('session', mustCall((accept, reject) => {
let stream;
accept().on('exec', mustCall((accept, reject, info) => {
assert(info.command === COMMAND,
`Wrong exec command: ${info.command}`);
stream = accept();
})).on('signal', mustCall((accept, reject, info) => {
assert(info.name === 'TERM',
`Wrong client signal name: ${info.name}`);
stream.exit(100);
stream.end();
conn.end();
}));
}));
}));
}));

client.on('ready', mustCall(() => {
client.exec(COMMAND, mustCall((err, stream) => {
assert(!err, `Unexpected exec error: ${err}`);
// Model the post-EOF state directly. The in-process test server
// closes the channel when it receives EOF, unlike OpenSSH.
stream.outgoing.state = 'eof';
stream.signal('TERM');
}));
}));
}

{
const { client, server } = setup('Exec with environment set');

Expand Down