Skip to content

Commit 9a67492

Browse files
committed
Fix exec command timeout not working
1 parent 2405dc0 commit 9a67492

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/ssh/nativeSSH.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,15 @@ function getSSHConfigPath() {
3636
return sshPath || 'ssh';
3737
}
3838

39-
function execCommand(commmad: string, args?: string[], options?: { timeout?: number }) {
40-
const process = cp.spawn(commmad, args, { ...options, windowsVerbatimArguments: true });
39+
function execCommand(command: string, args?: string[], options?: { timeout?: number }) {
40+
let abortController: AbortController | undefined;
41+
if (options?.timeout && options.timeout > 0) {
42+
abortController = new AbortController();
43+
setTimeout(() => {
44+
abortController?.abort();
45+
}, options.timeout);
46+
}
47+
const process = cp.spawn(command, args, { ...options, windowsVerbatimArguments: true, signal: abortController?.signal });
4148
const stdoutDataArr: string[] = [];
4249
const stderrDataArr: string[] = [];
4350
process.stdout.on('data', (data) => {

0 commit comments

Comments
 (0)