Repository navigation
AbortController/AbortSignal Triggering 'Error' Event in Child Process #46036
Description
Activity
I think we should fix the documentation. PR welcome :)
/cc @nodejs/child_process
- addedchild_processIssues and PRs related to the child_process subsystem.Issues and PRs related to the child_process subsystem.good first issueIssues that are suitable for first-time contributors.Issues that are suitable for first-time contributors.
on Jan 1, 2023 I think we should fix the documentation. PR welcome :)
In regards to how
AbortSignalis handled in Node.js's core modules, I agree; however,child_processalready deals with abortions and they do not triggererrorevents. Instead when a child process is aborted, the parent process is alerted in theexitorcloseevent via the signal argument. I think that ifAbortSignaltriggering an error (like it does in the rest of the core modules) will lead to more problems than if just alerts inexit/close's signal argument (in line withchild_process's modus operandi). At least for callback version; the promisify versions, you could make a good argument thatAbortSignalis explicit suppose to trigger a rejection.I think
AbortSignaltriggering an 'error' event will lead to either:- People having to duplicate handlers for aborting. One in the
errorhandler if the signal is from Node.js'sAbortSignaland another copy in theexitorclosehandler if the signal is from the local system. - People (lazily) squashing all
errorevents, because it's causing their program to crash and the handler is already inexitandcloseevent.
- People having to duplicate handlers for aborting. One in the
- added a commit that references this issue
on Jan 3, 2023 I am assuming that AbortSignal.abort() is suppose to act like child.kill( "SIGTERM" ) and not that the documentation is out-of-date.
The doc does mention AbortController would behave the same way but with the caveat of passing the AbortError
If the signal option is enabled, calling .abort() on the corresponding AbortController is similar to calling .kill() on the child process except the error passed to the callback will be an AbortError:
https://nodejs.org/api/child_process.html#child_processexeccommand-options-callbackBut nonetheless have put PR updating that specific line
- added a commit that references this issue
on Jan 7, 2023 - added 2 commits that reference this issue
on Jan 17, 2023 - added 2 commits that reference this issue
on Jan 26, 2023
Version
v18.9.0
Platform
Linux Mint 20.1
Subsystem
child_process
What steps will reproduce the bug?
exiteventerrorevent.The following code will generate the error for
spawn,execFile, andexecHow often does it reproduce? Is there a required condition?
This occurs every time, a child process is aborted via AbortSignal and it has not performed it's exit event.
What is the expected behavior?
What do you see instead?
Additional information
According to the documentation a child process
errorevent occurs only on:None of these conditions are true when the process is aborted via AbortSignal. If the child process is terminated via a
child.kill( "SIGTERM" )it does not trigger theerrorevent.I am assuming that
AbortSignal.abort()is suppose to act likechild.kill( "SIGTERM" )and not that the documentation is out-of-date.