Title: Memory leak when a Promise is stored on an Express request that's added to a domain · Issue #23862 · nodejs/node · GitHub
Open Graph Title: Memory leak when a Promise is stored on an Express request that's added to a domain · Issue #23862 · nodejs/node
X Title: Memory leak when a Promise is stored on an Express request that's added to a domain · Issue #23862 · nodejs/node
Description: Version: v10.12.0 Platform: Darwin zero-gravitas-lan.jetpants.com 18.0.0 Darwin Kernel Version 18.0.0: Wed Aug 22 20:13:40 PDT 2018; root:xnu-4903.201.2~1/RELEASE_X86_64 x86_64 Subsystem: domain The following code, which is a reduced tes...
Open Graph Description: Version: v10.12.0 Platform: Darwin zero-gravitas-lan.jetpants.com 18.0.0 Darwin Kernel Version 18.0.0: Wed Aug 22 20:13:40 PDT 2018; root:xnu-4903.201.2~1/RELEASE_X86_64 x86_64 Subsystem: domain Th...
X Description: Version: v10.12.0 Platform: Darwin zero-gravitas-lan.jetpants.com 18.0.0 Darwin Kernel Version 18.0.0: Wed Aug 22 20:13:40 PDT 2018; root:xnu-4903.201.2~1/RELEASE_X86_64 x86_64 Subsystem: domain Th...
Opengraph URL: https://github.com/nodejs/node/issues/23862
X: @github
Domain: github.com
IPv4 address: 140.82.113.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Memory leak when a Promise is stored on an Express request that's added to a domain","articleBody":"\u003c!--\r\nThank you for reporting a possible bug in Node.js.\r\n\r\nPlease fill in as much of the template below as you can.\r\n\r\nVersion: output of `node -v`\r\nPlatform: output of `uname -a` (UNIX), or version and 32 or 64-bit (Windows)\r\nSubsystem: if known, please specify the affected core module name\r\n\r\nIf possible, please provide code that demonstrates the problem, keeping it as\r\nsimple and free of external dependencies as you can.\r\n-->\r\n\r\n* **Version**: v10.12.0\r\n* **Platform**: Darwin zero-gravitas-lan.jetpants.com 18.0.0 Darwin Kernel Version 18.0.0: Wed Aug 22 20:13:40 PDT 2018; root:xnu-4903.201.2~1/RELEASE_X86_64 x86_64\r\n* **Subsystem**: domain\r\n\r\n\u003c!-- Please provide more details below this comment. -->\r\n\r\nThe following code, which is a reduced test case using functionality that's relied upon by the popular [Sentry](https://www.npmjs.com/package/@sentry/node) error reporting module, works fine in Node 8.12.0 but consistently leaks memory on each request in Node 10.12.0, 11.0.0, and 9.11.2:\r\n\r\n```js\r\n'use strict';\r\n\r\nconst domain = require('domain');\r\nconst app = require('express')();\r\n\r\napp.use((req, res, next) => {\r\n let requestDomain = domain.create();\r\n\r\n requestDomain.add(req);\r\n requestDomain.on('error', next);\r\n\r\n requestDomain.run(() => {\r\n next();\r\n });\r\n});\r\n\r\napp.get('/', (req, res) => {\r\n req.cachedPromise = new Promise(resolve => {\r\n let tenMebibyteString = 'a'.repeat(10 * 1024 * 1024);\r\n resolve(tenMebibyteString);\r\n });\r\n\r\n res.send('hi');\r\n});\r\n\r\napp.listen(5000);\r\n```\r\n\r\nI would expect the `req` object and its `req.cachedPromise` property to be GCed once the response is finished, since no references to it are being held. This is what happens in Node 8. But in Nodes 9, 10, and 11, `req.cachedPromise` never seems to be GCed, causing a steady memory leak.\r\n\r\nI first noticed this issue when I tried to upgrade a production service using Sentry to Node 10. It likely affects anyone who uses Sentry with Express and caches promises on the request object (or on any descendant of the request object).\r\n\r\nThe relevant code in Sentry is here: https://github.com/getsentry/sentry-javascript/blob/839326fbb498c669bd8b9c38bd93d39ca15b6266/packages/node/src/handlers.ts#L220-L229","author":{"url":"https://github.com/rgrove","@type":"Person","name":"rgrove"},"datePublished":"2018-10-25T00:45:08Z","url":"https://github.com/nodejs/node/issues/23862"}
| 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:3883143d-dc65-9050-9a02-e03b0a29e29e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A188:3709ED:DA33D8:13043E6:6B043DA7 |
| html-safe-nonce | 5e3bab30fc8b51d4aac23077b899b26e3a356e065af98e2415b2071010e1f2f4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMTg4OjM3MDlFRDpEQTMzRDg6MTMwNDNFNjo2QjA0M0RBNyIsInZpc2l0b3JfaWQiOiIyODgyNjkxMDQwNTEzNjM3Nzk5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 1c05d9c63773724394c73a9204fd2a35d5d4e7e1b37733abcb71de926a10a92c |
| hovercard-subject-tag | issue:373729920 |
| 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/23862/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b3150ca6f340258bd22d2c59dfa3cdb2541e1413078f5f50b8245a5eae643efb/nodejs/node/issues/23862 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b3150ca6f340258bd22d2c59dfa3cdb2541e1413078f5f50b8245a5eae643efb/nodejs/node/issues/23862 |
| og:image:alt | Version: v10.12.0 Platform: Darwin zero-gravitas-lan.jetpants.com 18.0.0 Darwin Kernel Version 18.0.0: Wed Aug 22 20:13:40 PDT 2018; root:xnu-4903.201.2~1/RELEASE_X86_64 x86_64 Subsystem: domain Th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rgrove |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9185ccfefd80c1ff2d9ddcdb0cd2becf46b5a1efbbf30741a895e4bb8de25e64 |
| 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 | 06dc448a76fe4751ac1db26524aefa3aa3e889a8 |
| 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