From 7dcb204b841b81155205ce48fac0c2a2bdbaa962 Mon Sep 17 00:00:00 2001 From: Francesco Trotta Date: Tue, 3 May 2022 21:48:30 +0200 Subject: [PATCH] lib: use `spawn` options for timeout in `execFile` --- lib/child_process.js | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/lib/child_process.js b/lib/child_process.js index 4b5da300b6295d..1ecf0356d6984b 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -305,9 +305,6 @@ function execFile(file, args = [], options, callback) { ...options }; - // Validate the timeout, if present. - validateTimeout(options.timeout); - // Validate maxBuffer, if present. validateMaxBuffer(options.maxBuffer); @@ -317,8 +314,10 @@ function execFile(file, args = [], options, callback) { cwd: options.cwd, env: options.env, gid: options.gid, + killSignal: options.killSignal, shell: options.shell, signal: options.signal, + timeout: options.timeout, uid: options.uid, windowsHide: !!options.windowsHide, windowsVerbatimArguments: !!options.windowsVerbatimArguments @@ -336,7 +335,6 @@ function execFile(file, args = [], options, callback) { let stderrLen = 0; let killed = false; let exited = false; - let timeoutId; let ex = null; @@ -346,11 +344,6 @@ function execFile(file, args = [], options, callback) { if (exited) return; exited = true; - if (timeoutId) { - clearTimeout(timeoutId); - timeoutId = null; - } - if (!callback) return; // merge chunks @@ -423,13 +416,6 @@ function execFile(file, args = [], options, callback) { } } - if (options.timeout > 0) { - timeoutId = setTimeout(function delayedKill() { - kill(); - timeoutId = null; - }, options.timeout); - } - if (child.stdout) { if (encoding) child.stdout.setEncoding(encoding);