Title: AbortSignal.any() leaks when any of the provided signal is long-lived · Issue #55351 · nodejs/node · GitHub
Open Graph Title: AbortSignal.any() leaks when any of the provided signal is long-lived · Issue #55351 · nodejs/node
X Title: AbortSignal.any() leaks when any of the provided signal is long-lived · Issue #55351 · nodejs/node
Description: Version v22.9.0 Platform Microsoft Windows NT 10.0.22631.0 x64 Subsystem No response What steps will reproduce the bug? const ac = new AbortController(); let i = 0; function run() { AbortSignal.any([ac.signal]); if (++i % 100_000 === 0) ...
Open Graph Description: Version v22.9.0 Platform Microsoft Windows NT 10.0.22631.0 x64 Subsystem No response What steps will reproduce the bug? const ac = new AbortController(); let i = 0; function run() { AbortSignal.any...
X Description: Version v22.9.0 Platform Microsoft Windows NT 10.0.22631.0 x64 Subsystem No response What steps will reproduce the bug? const ac = new AbortController(); let i = 0; function run() { AbortSignal.any...
Opengraph URL: https://github.com/nodejs/node/issues/55351
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"AbortSignal.any() leaks when any of the provided signal is long-lived","articleBody":"### Version\n\nv22.9.0\n\n### Platform\n\n```text\nMicrosoft Windows NT 10.0.22631.0 x64\n```\n\n\n### Subsystem\n\n_No response_\n\n### What steps will reproduce the bug?\n\n```js\r\nconst ac = new AbortController();\r\n\r\nlet i = 0;\r\nfunction run() {\r\n AbortSignal.any([ac.signal]);\r\n if (++i % 100_000 === 0) {\r\n const mem = process.memoryUsage().rss / 1024 / 1024;\r\n const kDependantSignals = Object.getOwnPropertySymbols(ac.signal).filter(\r\n (s) =\u003e s.toString() === 'Symbol(kDependantSignals)'\r\n )[0];\r\n const signals = ac.signal[kDependantSignals];\r\n console.log(`${i} - ${mem.toFixed(2)} MiB - ${signals?.size} signals`);\r\n }\r\n setImmediate(run);\r\n}\r\nrun();\r\n```\n\n### How often does it reproduce? Is there a required condition?\n\nAlways\n\n### What is the expected behavior? Why is that the expected behavior?\n\nAbortSignal.any should not case memory leaks\n\n### What do you see instead?\n\n```\r\n❯ node ..\\test.js\r\nnode .\\test.js\r\n100000 - 82.29 MiB - 100000 signals\r\n200000 - 97.98 MiB - 200000 signals\r\n300000 - 126.98 MiB - 300000 signals\r\n400000 - 131.91 MiB - 400000 signals\r\n500000 - 152.07 MiB - 500000 signals\r\n600000 - 162.52 MiB - 600000 signals\r\n700000 - 208.69 MiB - 700000 signals\r\n800000 - 219.15 MiB - 800000 signals\r\n900000 - 221.80 MiB - 900000 signals\r\n1000000 - 244.98 MiB - 1000000 signals\r\n1100000 - 285.09 MiB - 1100000 signals\r\n1200000 - 265.71 MiB - 1200000 signals\r\n1300000 - 265.71 MiB - 1300000 signals\r\n1400000 - 311.45 MiB - 1400000 signals\r\n1500000 - 378.47 MiB - 1500000 signals\r\n1600000 - 377.95 MiB - 1600000 signals\r\n1700000 - 378.01 MiB - 1700000 signals\r\n1800000 - 378.65 MiB - 1800000 signals\r\n1900000 - 406.42 MiB - 1900000 signals\r\n2000000 - 423.68 MiB - 2000000 signals\r\n2100000 - 503.71 MiB - 2100000 signals\r\n2200000 - 503.72 MiB - 2200000 signals\r\n2300000 - 464.14 MiB - 2300000 signals\r\n2400000 - 464.20 MiB - 2400000 signals\r\n2500000 - 464.20 MiB - 2500000 signals\r\n2600000 - 464.20 MiB - 2600000 signals\r\n2700000 - 481.40 MiB - 2700000 signals\r\n2800000 - 548.31 MiB - 2800000 signals\r\n2900000 - 611.93 MiB - 2900000 signals\r\n3000000 - 678.66 MiB - 3000000 signals\r\n3100000 - 685.27 MiB - 3100000 signals\r\n3200000 - 685.36 MiB - 3200000 signals\r\n3300000 - 685.36 MiB - 3300000 signals\r\n3400000 - 685.36 MiB - 3400000 signals\r\n3500000 - 685.36 MiB - 3500000 signals\r\n3600000 - 686.01 MiB - 3600000 signals\r\n3700000 - 686.08 MiB - 3700000 signals\r\n3800000 - 748.08 MiB - 3800000 signals\r\n3900000 - 775.59 MiB - 3900000 signals\r\n...\r\n```\n\n### Additional information\n\nIt's pretty clear that `AbortSignal.any` attaches the combined signal to all its parent signals. But it only gets removed if the parent signals are actually aborted. If there is a long living signal among the parents, for instance something like a SIGINT handler, then it keeps accumulating WeakRefs to no longer existing `AbortSignal`s.\r\n\r\nRelated issues:\r\n- Related deno issue: https://github.com/denoland/deno/issues/24842\r\n- Partly related issue: https://github.com/nodejs/node/issues/48419\r\n - Particularly case 3 of https://github.com/nodejs/node/issues/48419#issuecomment-2215484061\r\n- Different issue: https://github.com/nodejs/node/issues/55328\r\n - Another leak when not properly removing listeners from `AbortSignal` returned by `AbortSignal.any`\r\n- Probably not an issue at all: https://github.com/nodejs/node/issues/54614","author":{"url":"https://github.com/mika-fischer","@type":"Person","name":"mika-fischer"},"datePublished":"2024-10-10T14:43:52.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":8},"url":"https://github.com/55351/node/issues/55351"}
| 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:3368338d-14ad-c575-ec54-443d7710c636 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | ACFC:14D8D:9421F4:C8595E:6A4C4667 |
| html-safe-nonce | d358a2f448e25acd87161c3ab80f3cece2e8c3730d029af625a0e5763b2dd166 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQ0ZDOjE0RDhEOjk0MjFGNDpDODU5NUU6NkE0QzQ2NjciLCJ2aXNpdG9yX2lkIjoiMjIwOTIzMzEyNDc0MjQxNTk3NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 611526c240f3e9b1d54b0a2fc503fe78a8d31c10cd2b0f91948105c74af438f7 |
| hovercard-subject-tag | issue:2579077659 |
| 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/55351/issue_layout |
| twitter:image | https://opengraph.githubassets.com/47f91d67fd6dd3490de8110ae4c6f62307a7de6dd850db2a50b619efac0987a2/nodejs/node/issues/55351 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/47f91d67fd6dd3490de8110ae4c6f62307a7de6dd850db2a50b619efac0987a2/nodejs/node/issues/55351 |
| og:image:alt | Version v22.9.0 Platform Microsoft Windows NT 10.0.22631.0 x64 Subsystem No response What steps will reproduce the bug? const ac = new AbortController(); let i = 0; function run() { AbortSignal.any... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mika-fischer |
| 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 | 3996b3b83990e134be6c099ab9a7f48f140ae80f |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width