Know when a process ended due to the `child_process.spawn()` `timeout` option
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 122k
- Forks
- 37.3k
- Avg merge
- 4d 2h
- Merged PRs (30d)
- 283
Description
What is the problem this feature will solve?
When a process ends due to the timeout option of child_process.spawn(), there is no way to know whether that termination was due to the timeout. A SIGTERM is sent to the process, but that's pretty much it.
import {spawn} from 'node:child_process'
const childProcess = spawn('node', ['-e', 'setTimeout(() => {}, 1e7)'], {
timeout: 2e3,
stdio: 'inherit', // no stdout/stderr
})
childProcess.on('exit', (exitCode, signal) => {
console.log({exitCode, signal}) // { exitCode: null, signal: 'SIGTERM' }
})
This makes debugging harder. Some users might be left wondering why the process ended if they don't pay attention to the timeout option.
What is the feature you are proposing to solve the problem?
Having a way to know whether the process ended due to the timeout option. Any implementation would work. Some potential ideas:
timeoutevent onchildProcess- third boolean argument
timedOutpassed to theexitevent - emit an
errorevent witherror.code: 'ETIMEDOUT'onchildProcess. This is a breaking change since many users are currently listening forerrorevents, so would probably not be a good idea. childProcess.timedOut = truechildProcess.timedOut()returning a boolean
What alternatives have you considered?
One could possibly set a manual timeout like the following.
let timedOut = false
setTimeout(() => {
timedOut = true
}, 2e3)
However, it defeats some of the convenience of the timeout option, since that one might as well call childProcess.kill() themselves then. Also, it is slightly unreliable since an unrelated SIGTERM could theoretically have been sent at the exact same time.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Begin with the child_process.spawn() timeout and exit event behavior shown in the example. Review the proposed timeout event, exit metadata, error, and property approaches, then resolve on a documented way for users to distinguish timeout-triggered termination from an unrelated SIGTERM.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 45/100