Title: Inconsistent validation of custom signals · Issue #44749 · nodejs/node · GitHub
Open Graph Title: Inconsistent validation of custom signals · Issue #44749 · nodejs/node
X Title: Inconsistent validation of custom signals · Issue #44749 · nodejs/node
Description: Version 18.9.0 Platform Darwin Subsystem child_process os What steps will reproduce the bug? In the current implementation, spawn and related functions throw synchronous errors for invalid signals, e.g.: import { spawn } from 'node:child...
Open Graph Description: Version 18.9.0 Platform Darwin Subsystem child_process os What steps will reproduce the bug? In the current implementation, spawn and related functions throw synchronous errors for invalid signals,...
X Description: Version 18.9.0 Platform Darwin Subsystem child_process os What steps will reproduce the bug? In the current implementation, spawn and related functions throw synchronous errors for invalid signals,...
Opengraph URL: https://github.com/nodejs/node/issues/44749
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inconsistent validation of custom signals","articleBody":"### Version\r\n\r\n18.9.0\r\n\r\n### Platform\r\n\r\nDarwin\r\n\r\n### Subsystem\r\n\r\nchild_process\r\nos\r\n\r\n### What steps will reproduce the bug?\r\n\r\nIn the current implementation, `spawn` and related functions throw synchronous errors for invalid signals, e.g.:\r\n\r\n```js\r\nimport { spawn } from 'node:child_process';\r\n\r\n// TypeError [ERR_UNKNOWN_SIGNAL]\r\nspawn(process.execPath, ['-v'], { killSignal: 12345 });\r\n```\r\n\r\nAnyway, it's easy to define custom signals that pass the validation:\r\n\r\n```js\r\nimport { spawn } from 'node:child_process';\r\nimport { constants } from 'node:os';\r\n\r\nconstants.signals.FOOBAR = 12345;\r\n// no error\r\nspawn(process.execPath, ['-v'], { killSignal: 12345 });\r\n```\r\n\r\nThe same applies when signals are identified by name, i.e:\r\n\r\n```js\r\nimport { spawn } from 'node:child_process';\r\n\r\n// TypeError [ERR_UNKNOWN_SIGNAL]\r\nspawn(process.execPath, ['-v'], { killSignal: 'FOOBAR' });\r\n```\r\n\r\nand\r\n\r\n```js\r\nimport { spawn } from 'node:child_process';\r\nimport { constants } from 'node:os';\r\n\r\nconstants.signals.FOOBAR = 12345;\r\n// no error\r\nspawn(process.execPath, ['-v'], { killSignal: 'FOOBAR' });\r\n```\r\n\r\n**but** if a custom signal is added after the internal mapping of numeric codes to names signals has been generated, validation fails for numeric codes (but not for signal names):\r\n\r\n```js\r\nimport { spawn } from 'node:child_process';\r\nimport { constants } from 'node:os';\r\n\r\nspawn(process.execPath, ['-v'], { killSignal: 1 });\r\nconstants.signals.FOOBAR = 12345;\r\nspawn(process.execPath, ['-v'], { killSignal: 'FOOBAR' }); // no error\r\nspawn(process.execPath, ['-v'], { killSignal: 12345 }); // TypeError [ERR_UNKNOWN_SIGNAL]\r\n```\r\n\r\nThis strikes to me as issue of improper memoization:\r\n\r\nhttps://github.com/nodejs/node/blob/9ae2af4aaebe5c6efad774989c4958ba6d32c0fd/lib/internal/util.js#L272-L283\r\n\r\nwhere `signalsToNamesMapping` never changes once created.\r\n\r\nOn the other hand, I'm not convinced that the current behavior - being able to add, remove, and change signals at will - is intended. If it is, then the validation logic should be fixed. If it is not, then `constants.signals` should be better frozen to prevent changes.\r\n\r\n### How often does it reproduce? Is there a required condition?\r\n\r\nAll the time.\r\n\r\n### What is the expected behavior?\r\n\r\nEither custom numeric signals should always be accepted as valid, or they should always be rejected. If they should be rejected, then custom string signals should be rejected, too.\r\n\r\n### What do you see instead?\r\n\r\nInconsistent behavior, depending on (possibly unrelated) previous operations.\r\n\r\n### Additional information\r\n\r\n_No response_","author":{"url":"https://github.com/fasttime","@type":"Person","name":"fasttime"},"datePublished":"2022-09-22T17:50:07.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/44749/node/issues/44749"}
| 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:83ff1d7b-14ef-e0f9-6bca-eb85a08eefab |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BBC2:306DA5:482F29:6191F5:6A4C764A |
| html-safe-nonce | b5f894945ae8beb8dd24d429d18850ffd309ede8b4cf63f5574be1c1eeb86c30 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQkMyOjMwNkRBNTo0ODJGMjk6NjE5MUY1OjZBNEM3NjRBIiwidmlzaXRvcl9pZCI6IjM0Mzc4MzczMjYxMDg4ODI1MDYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | f768f098e20c2d56ddf1bc9873c9c217f9a3ac1cae12db439087181d30922df1 |
| hovercard-subject-tag | issue:1382811018 |
| 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/44749/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a5c2fb484ded6284d99726c162869b500ff3bf444a6ff84e639577062a5b4f9a/nodejs/node/issues/44749 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a5c2fb484ded6284d99726c162869b500ff3bf444a6ff84e639577062a5b4f9a/nodejs/node/issues/44749 |
| og:image:alt | Version 18.9.0 Platform Darwin Subsystem child_process os What steps will reproduce the bug? In the current implementation, spawn and related functions throw synchronous errors for invalid signals,... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | fasttime |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3d11bb817438277de2a940854450e83a7d32b6aeb5014e9e6b00a6423900251c |
| 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 | 56ac743bebb13694b888673bb7257f4b97a4b7fd |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width