René's URL Explorer Experiment


Title: Racing immediately-resolving Promises leads to memory leak · Issue #51452 · nodejs/node · GitHub

Open Graph Title: Racing immediately-resolving Promises leads to memory leak · Issue #51452 · nodejs/node

X Title: Racing immediately-resolving Promises leads to memory leak · Issue #51452 · nodejs/node

Description: Version 21.5.0 Platform Linux penguin 6.1.55-06877-gc83437f2949f #1 SMP PREEMPT_DYNAMIC Thu Dec 14 19:17:39 PST 2023 x86_64 GNU/Linux Subsystem async_hooks or async/await What steps will reproduce the bug? Run the following code. Failure...

Open Graph Description: Version 21.5.0 Platform Linux penguin 6.1.55-06877-gc83437f2949f #1 SMP PREEMPT_DYNAMIC Thu Dec 14 19:17:39 PST 2023 x86_64 GNU/Linux Subsystem async_hooks or async/await What steps will reproduce ...

X Description: Version 21.5.0 Platform Linux penguin 6.1.55-06877-gc83437f2949f #1 SMP PREEMPT_DYNAMIC Thu Dec 14 19:17:39 PST 2023 x86_64 GNU/Linux Subsystem async_hooks or async/await What steps will reproduce ...

Opengraph URL: https://github.com/nodejs/node/issues/51452

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Racing immediately-resolving Promises leads to memory leak","articleBody":"### Version\r\n\r\n21.5.0\r\n\r\n### Platform\r\n\r\nLinux penguin 6.1.55-06877-gc83437f2949f #1 SMP PREEMPT_DYNAMIC Thu Dec 14 19:17:39 PST 2023 x86_64 GNU/Linux\r\n\r\n### Subsystem\r\n\r\nasync_hooks or async/await\r\n\r\n### What steps will reproduce the bug?\r\n\r\nRun the following code. Failure is quicker and less likely to interfere with system stability if you run with a low heap ceiling like this, but it will fail without...\r\n\r\n```\r\nnode --max-old-space-size=16 test/examples/ephemeralPromiseMemoryLeak.js\r\n```\r\n\r\n```js\r\n//ephemeralPromiseMemoryLeak.js\r\n\r\nasync function promiseValue(value) {\r\n  return value;\r\n}\r\n\r\nasync function run() {\r\n  for (;;) {\r\n    await Promise.race([promiseValue(\"foo\"), promiseValue(\"bar\")]);\r\n  }\r\n}\r\n\r\nrun();\r\n```\r\n\r\nAn equivalent OOM is created if you substitute `Promise.any` for `Promise.race`...\r\n\r\n```js\r\nasync function promiseValue(value) {\r\n  return value;\r\n}\r\n\r\nasync function run() {\r\n  for (;;) {\r\n    await Promise.any([promiseValue(\"foo\"), promiseValue(\"bar\")]);\r\n  }\r\n}\r\n\r\nrun();\r\n```\r\n\r\n### How often does it reproduce? Is there a required condition?\r\n\r\nIt always fails.\r\n\r\n### What is the expected behavior? Why is that the expected behavior?\r\n\r\nI would expect it not to accumulate references in memory and fail.\r\n\r\n### What do you see instead?\r\n\r\nFails with the following error\r\n\r\n```sh\r\n✗ node test/examples/ephemeralPromiseMemoryLeak.js\r\n\r\n\u003c--- Last few GCs ---\u003e\r\n\r\n[31511:0x6de4330]    39874 ms: Mark-Compact (reduce) 2048.2 (2083.6) -\u003e 2047.3 (2083.9) MB, 1308.67 / 0.00 ms  (average mu = 0.071, current mu = 0.001) allocation failure; scavenge might not succeed\r\n\r\n\r\n\u003c--- JS stacktrace ---\u003e\r\n\r\nFATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory\r\n----- Native stack trace -----\r\n\r\n 1: 0xcc062a node::OOMErrorHandler(char const*, v8::OOMDetails const\u0026) [node]\r\n 2: 0x104eb90 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, v8::OOMDetails const\u0026) [node]\r\n 3: 0x104ee77 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, v8::OOMDetails const\u0026) [node]\r\n 4: 0x126e0b5  [node]\r\n 5: 0x126e58e  [node]\r\n 6: 0x12837b6 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::internal::GarbageCollectionReason, char const*) [node]\r\n 7: 0x12842d9  [node]\r\n 8: 0x12848e8  [node]\r\n 9: 0x19d4311  [node]\r\n[1]    31511 abort (core dumped)  node test/examples/ephemeralPromiseMemoryLeak.js\r\n```\r\n\r\n### Additional information\r\n\r\nIf the promiseValue call incorporates an explicit scheduling on the event loop, there is no memory leak...\r\n\r\n```js\r\n// setImmediateNoLeak.js\r\n\r\nfunction promiseValue(value) {\r\n  return new Promise((resolve) =\u003e {\r\n    setImmediate(() =\u003e resolve(value));\r\n  });\r\n}\r\n\r\nasync function run() {\r\n  for (;;) {\r\n    await Promise.race([promiseValue(\"foo\"), promiseValue(\"bar\")]);\r\n  }\r\n}\r\n\r\nrun();\r\n```\r\n\r\nIf the promiseValue call isn't composed via a Promise.race there is no leak...\r\n\r\n```js\r\n// noRaceNoLeak.js\r\n\r\nasync function promiseValue(value) {\r\n  return value;\r\n}\r\n\r\nasync function run() {\r\n  for (;;) {\r\n    await promiseValue(\"foo\");\r\n    await promiseValue(\"bar\");\r\n  }\r\n}\r\n\r\nrun();\r\n```\r\n\r\nMaybe obviously, but putting it here for completeness, if you don't use an async await loop, but compose the loop itself with setImmediate there is no leak...\r\n\r\n\r\n```js\r\n// noLoopNoLeak.js\r\n\r\nasync function promiseValue(value) {\r\n  return value;\r\n}\r\n\r\nasync function doRace() {\r\n  await Promise.race([promiseValue(\"foo\"), promiseValue(\"bar\")]);\r\n}\r\n\r\nfunction run() {\r\n  doRace().then(() =\u003e setImmediate(run));\r\n}\r\n\r\nrun();\r\n```","author":{"url":"https://github.com/cefn","@type":"Person","name":"cefn"},"datePublished":"2024-01-13T22:50:04.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":12},"url":"https://github.com/51452/node/issues/51452"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:f7c5cf34-2765-4f9a-c585-b82e4b7daeb3
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idCDE2:1171B:116627C:174EB14:6A4D8E73
html-safe-nonce6fd5e4c1ac6597d12eac7d43dd8941f9913bd96732234e63dc57808bbbe5cd86
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDREUyOjExNzFCOjExNjYyN0M6MTc0RUIxNDo2QTREOEU3MyIsInZpc2l0b3JfaWQiOiIzMjE5MTc5NTM5MjEzNTUzNzkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac03d487d2a4e6690d18b255fe0b1887dd943ed91c3c20397522c03fc2c943d59b
hovercard-subject-tagissue:2080502320
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/51452/issue_layout
twitter:imagehttps://opengraph.githubassets.com/298d89319a69901202aa93d5de6cccbbe4d306563ca9108384f4f6fa161ba080/nodejs/node/issues/51452
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/298d89319a69901202aa93d5de6cccbbe4d306563ca9108384f4f6fa161ba080/nodejs/node/issues/51452
og:image:altVersion 21.5.0 Platform Linux penguin 6.1.55-06877-gc83437f2949f #1 SMP PREEMPT_DYNAMIC Thu Dec 14 19:17:39 PST 2023 x86_64 GNU/Linux Subsystem async_hooks or async/await What steps will reproduce ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamecefn
hostnamegithub.com
expected-hostnamegithub.com
None06b8a6144231bf3a234f1c2e9993861e07ce98a905912b114aa386c2d7e84b33
turbo-cache-controlno-preview
go-importgithub.com/nodejs/node git https://github.com/nodejs/node.git
octolytics-dimension-user_id9950313
octolytics-dimension-user_loginnodejs
octolytics-dimension-repository_id27193779
octolytics-dimension-repository_nwonodejs/node
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id27193779
octolytics-dimension-repository_network_root_nwonodejs/node
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release74e2a9c78f1e38588de4f25885878349d721eedf
ui-targetcanary-2
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/nodejs/node/issues/51452#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnodejs%2Fnode%2Fissues%2F51452
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnodejs%2Fnode%2Fissues%2F51452
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=nodejs%2Fnode
Reloadhttps://github.com/nodejs/node/issues/51452
Reloadhttps://github.com/nodejs/node/issues/51452
Reloadhttps://github.com/nodejs/node/issues/51452
Please reload this pagehttps://github.com/nodejs/node/issues/51452
nodejs https://github.com/nodejs
nodehttps://github.com/nodejs/node
Please reload this pagehttps://github.com/nodejs/node/issues/51452
Notifications https://github.com/login?return_to=%2Fnodejs%2Fnode
Fork 36k https://github.com/login?return_to=%2Fnodejs%2Fnode
Star 118k https://github.com/login?return_to=%2Fnodejs%2Fnode
Code https://github.com/nodejs/node
Issues 1.4k https://github.com/nodejs/node/issues
Pull requests 963 https://github.com/nodejs/node/pulls
Actions https://github.com/nodejs/node/actions
Projects https://github.com/nodejs/node/projects
Security and quality 0 https://github.com/nodejs/node/security
Insights https://github.com/nodejs/node/pulse
Code https://github.com/nodejs/node
Issues https://github.com/nodejs/node/issues
Pull requests https://github.com/nodejs/node/pulls
Actions https://github.com/nodejs/node/actions
Projects https://github.com/nodejs/node/projects
Security and quality https://github.com/nodejs/node/security
Insights https://github.com/nodejs/node/pulse
Racing immediately-resolving Promises leads to memory leakhttps://github.com/nodejs/node/issues/51452#top
confirmed-bugIssues with confirmed bugs.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22confirmed-bug%22
performanceIssues and PRs related to the performance of Node.js.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22performance%22
promisesIssues and PRs related to ECMAScript promises.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22promises%22
https://github.com/cefn
cefnhttps://github.com/cefn
on Jan 13, 2024https://github.com/nodejs/node/issues/51452#issue-2080502320
#1https://github.com/nodejs/node/pull/1
confirmed-bugIssues with confirmed bugs.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22confirmed-bug%22
performanceIssues and PRs related to the performance of Node.js.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22performance%22
promisesIssues and PRs related to ECMAScript promises.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22promises%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.