Title: Excessive memory usage with `AsyncLocalStorage` and debugger attached in Node < v18 · Issue #47406 · nodejs/node · GitHub
Open Graph Title: Excessive memory usage with `AsyncLocalStorage` and debugger attached in Node < v18 · Issue #47406 · nodejs/node
X Title: Excessive memory usage with `AsyncLocalStorage` and debugger attached in Node < v18 · Issue #47406 · nodejs/node
Description: Version v16.20.0 Platform macOS Subsystem No response What steps will reproduce the bug? Using express@4.17.1 although I doubt it matters: app.js const express = require("express"); const { AsyncLocalStorage } = require("async_hooks"); c...
Open Graph Description: Version v16.20.0 Platform macOS Subsystem No response What steps will reproduce the bug? Using express@4.17.1 although I doubt it matters: app.js const express = require("express"); const { AsyncLo...
X Description: Version v16.20.0 Platform macOS Subsystem No response What steps will reproduce the bug? Using express@4.17.1 although I doubt it matters: app.js const express = require("express"); const...
Opengraph URL: https://github.com/nodejs/node/issues/47406
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Excessive memory usage with `AsyncLocalStorage` and debugger attached in Node \u003c v18","articleBody":"### Version\r\n\r\nv16.20.0\r\n\r\n### Platform\r\n\r\nmacOS\r\n\r\n### Subsystem\r\n\r\n_No response_\r\n\r\n### What steps will reproduce the bug?\r\n\r\nUsing express@4.17.1 although I doubt it matters:\r\n\r\n`app.js`\r\n\r\n```ts\r\nconst express = require(\"express\");\r\nconst { AsyncLocalStorage } = require(\"async_hooks\");\r\n\r\nconst asyncLocalStorage = new AsyncLocalStorage();\r\nconst app = express();\r\n\r\nsetInterval(() => {\r\n console.log(\"Memory usage: \", process.memoryUsage().rss / 1024 / 1024);\r\n}, 1000);\r\n\r\napp.use((req, res, next) => {\r\n asyncLocalStorage.run(new Map(), () => {\r\n asyncLocalStorage.getStore().set(\"request\", req);\r\n next();\r\n });\r\n});\r\n\r\nasync function random() {\r\n return new Promise((resolve) => {\r\n setImmediate(() => {\r\n resolve(Math.random());\r\n });\r\n });\r\n}\r\n\r\napp.get(\"/async\", async function (req, res) {\r\n res.send(\"Ok\" + (await random()));\r\n});\r\n\r\napp.listen(3001, function () {\r\n console.log(\"Web server listening on port 3001\");\r\n});\r\n```\r\n\r\n- Run `node --inspect-brk app.js`\r\n- Attach the Chrome debugger and click Resume\r\n- Load test the async endpoint (`autocannon http://localhost:3001/async`)\r\n\r\n### How often does it reproduce? Is there a required condition?\r\n\r\nEvery time\r\n\r\n### What is the expected behavior? Why is that the expected behavior?\r\n\r\n_No response_\r\n\r\n### What do you see instead?\r\n\r\nWith the default settings for `autocannon`, memory peaks when the load test stops at over 1.2GB. \r\n\r\nIf I do any of the following, the displayed memory usage never goes above 200MB.\r\n- Use Node v18\r\n- Don't attach the debugger\r\n- Avoid async\r\n\r\nIf you disconnect the debugger and run the load test again, the memory doesn't increase uncontrollably.\r\n\r\n### Additional information\r\n\r\n_No response_","author":{"url":"https://github.com/timfish","@type":"Person","name":"timfish"},"datePublished":"2023-04-04T14:41:28Z","url":"https://github.com/nodejs/node/issues/47406"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:64fff662-99f0-1498-003e-eb0f47c931c5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E448:94A1C:675A63:8B3D9B:6B04A9F9 |
| html-safe-nonce | 0dfe3669f68010d520a9854d2cf4eee2e9170cc13e5a72bc6b5684cc81792faa |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNDQ4Ojk0QTFDOjY3NUE2Mzo4QjNEOUI6NkIwNEE5RjkiLCJ2aXNpdG9yX2lkIjoiMzcxMjg5NDE0NDIyMjYzNjUzNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | abecb5df88a192c7165fe708e38d75ccc6aec7254a6b0547e9b1b478ee7c55e5 |
| hovercard-subject-tag | issue:1654029125 |
| 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/47406/issue_layout |
| twitter:image | https://opengraph.githubassets.com/eed2502e5fae688db1a4725a5cc19d9d351508e6536e4b372aa52483d08ba740/nodejs/node/issues/47406 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/eed2502e5fae688db1a4725a5cc19d9d351508e6536e4b372aa52483d08ba740/nodejs/node/issues/47406 |
| og:image:alt | Version v16.20.0 Platform macOS Subsystem No response What steps will reproduce the bug? Using express@4.17.1 although I doubt it matters: app.js const express = require("express"); const { AsyncLo... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | timfish |
| hostname | github.com |
| expected-hostname | github.com |
| None | 188497a0f45a7aa8f7c866faa1950d1a7f8d82b59416adf549b222ad1d1dd19b |
| 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 | 557cfbac6cdb532730c95c90f2cefdc0c4128029 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width