Title: Know when a process ended due to the `child_process.spawn()` `timeout` option · Issue #51561 · nodejs/node · GitHub
Open Graph Title: Know when a process ended due to the `child_process.spawn()` `timeout` option · Issue #51561 · nodejs/node
X Title: Know when a process ended due to the `child_process.spawn()` `timeout` option · Issue #51561 · nodejs/node
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 pr...
Open Graph 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 SIGTE...
X 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 SIGTE...
Opengraph URL: https://github.com/nodejs/node/issues/51561
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Know when a process ended due to the `child_process.spawn()` `timeout` option ","articleBody":"### What is the problem this feature will solve?\r\n\r\nWhen 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.\r\n\r\n```js\r\nimport {spawn} from 'node:child_process'\r\n\r\nconst childProcess = spawn('node', ['-e', 'setTimeout(() => {}, 1e7)'], {\r\n timeout: 2e3, \r\n stdio: 'inherit', // no stdout/stderr\r\n})\r\nchildProcess.on('exit', (exitCode, signal) => {\r\n console.log({exitCode, signal}) // { exitCode: null, signal: 'SIGTERM' }\r\n})\r\n```\r\n\r\nThis makes debugging harder. Some users might be left wondering why the process ended if they don't pay attention to the `timeout` option.\r\n\r\n### What is the feature you are proposing to solve the problem?\r\n\r\nHaving a way to know whether the process ended due to the `timeout` option. Any implementation would work. Some potential ideas:\r\n - `timeout` event on `childProcess`\r\n - third boolean argument `timedOut` passed to the `exit` event\r\n - emit an `error` event with `error.code: 'ETIMEDOUT'` on `childProcess`. This is a breaking change since many users are currently listening for `error` events, so would probably not be a good idea.\r\n - `childProcess.timedOut = true`\r\n - `childProcess.timedOut()` returning a boolean\r\n\r\n### What alternatives have you considered?\r\n\r\nOne could possibly set a manual timeout like the following.\r\n\r\n```js\r\nlet timedOut = false\r\nsetTimeout(() => {\r\n timedOut = true\r\n}, 2e3)\r\n```\r\n\r\nHowever, 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.","author":{"url":"https://github.com/ehmicky","@type":"Person","name":"ehmicky"},"datePublished":"2024-01-24T21:05:48Z","url":"https://github.com/nodejs/node/issues/51561"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:1331d5a9-555c-7c26-7136-f441efef00fd |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C3CE:169E62:91A26B:BD0A97:6AED38EA |
| html-safe-nonce | 3b08ccded6542356b6fc5f069420d1fd1aed3acbe0c5f599f6b0dad0e5ee4e07 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDM0NFOjE2OUU2Mjo5MUEyNkI6QkQwQTk3OjZBRUQzOEVBIiwidmlzaXRvcl9pZCI6IjQxOTc1ODU3MDg5OTUzOTM3NzAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c844ba254390a105c2230fe14a676d3ce7389e8dfe237ef22e3ff885b31a4fe1 |
| hovercard-subject-tag | issue:2099105948 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/51561/issue_layout |
| twitter:image | https://opengraph.githubassets.com/162bfd1e93477c041518dadeb409c3499b3210ca74796f144839c47d7163fbf1/nodejs/node/issues/51561 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/162bfd1e93477c041518dadeb409c3499b3210ca74796f144839c47d7163fbf1/nodejs/node/issues/51561 |
| og:image:alt | 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 SIGTE... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ehmicky |
| hostname | github.com |
| expected-hostname | github.com |
| None | 26c92a9388ddfad3fa88d132b5d5f0b4747030233dcc4e5efb05f1cbae152184 |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | c629ad99c254d306375fc8354d04321c2c362236 |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width