Title: node:http client span never ends when the response is destroyed without an error (res.destroy()) · Issue #25469 · getsentry/sentry-javascript · GitHub
Open Graph Title: node:http client span never ends when the response is destroyed without an error (res.destroy()) · Issue #25469 · getsentry/sentry-javascript
X Title: node:http client span never ends when the response is destroyed without an error (res.destroy()) · Issue #25469 · getsentry/sentry-javascript
Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using the latest SDK release https://github.com/...
Open Graph Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th...
X Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/25469
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"node:http client span never ends when the response is destroyed without an error (res.destroy())","articleBody":"\n### Is there an existing issue for this?\n\n- [x] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues\n- [x] I have reviewed the documentation https://docs.sentry.io/\n- [x] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases\n\n### How do you use Sentry?\n\nSentry SaaS (sentry.io)\n\n### Which SDK are you using?\n\n@sentry/node\n\n### SDK Version\n\n11.8.0 (latest at the time of writing)\n\n### Framework Version\n\nNode v25.8.0, plain `node:http`, no framework\n\n### Link to Sentry event\n\nn/a, local repro (the DSN points at a local sink on 127.0.0.1)\n\n### Reproduction Example/SDK Setup\n\nSelf-contained, only needs `npm i @sentry/node`. It starts a local server that sends headers and\nthen streams a body, and a local DSN sink that collects the envelopes.\n\n```js\n// Repro: http.client span is never ended when the response is destroyed mid-body.\n// Usage: npm i @sentry/node && node nodehttp-repro.mjs\n// Everything is local (127.0.0.1); no real DSN is used.\nimport * as Sentry from '@sentry/node';\nimport http from 'node:http';\n\n// Local DSN sink: collects envelopes so we can see which spans were actually sent.\nconst sentSpans = new Map(); // url.full -> status, for http.client spans that reached the sink\nconst collect = o => {\n if (!o || typeof o !== 'object') return;\n const a = o.attributes || {};\n const url = a['url.full']?.value ?? a['url.full'] ?? o.data?.['url.full'];\n const op = a['sentry.op']?.value ?? a['sentry.op'] ?? o.op;\n if (op === 'http.client' && url) sentSpans.set(url, o.status);\n for (const v of Object.values(o)) if (v && typeof v === 'object') collect(v);\n};\nconst sink = http.createServer((req, res) => {\n let body = '';\n req.on('data', c => (body += c));\n req.on('end', () => {\n for (const line of body.split('\\n')) { try { collect(JSON.parse(line)); } catch {} }\n res.end('{}');\n });\n});\nawait new Promise(r => sink.listen(0, '127.0.0.1', r));\n\nSentry.init({\n dsn: `http://k@127.0.0.1:${sink.address().port}/1`,\n tracesSampleRate: 1,\n // do not trace the sink itself\n ignoreOutgoingRequests: url => url.includes(`:${sink.address().port}`),\n});\n\nconst ended = new Map(); // url.full -> status\nSentry.getClient().on('spanEnd', span => {\n const j = Sentry.spanToJSON(span);\n const url = j.attributes?.['url.full'] ?? j.data?.['url.full'];\n const op = j.attributes?.['sentry.op'] ?? j.op;\n if (op === 'http.client' && url) ended.set(url, j.status);\n});\n\n// Server that streams a slow body (headers sent, body never finishes on its own).\nconst srv = http.createServer((req, res) => {\n res.writeHead(200);\n res.write('first chunk');\n if (req.url.startsWith('/full')) setTimeout(() => res.end('rest'), 50);\n});\nawait new Promise(r => srv.listen(0, '127.0.0.1', r));\nconst port = srv.address().port;\n\nconst cases = {\n full: res => { res.on('data', () => {}); },\n 'res.destroy()': res => { res.once('data', () => res.destroy()); },\n 'res.destroy(new Error())': res => { res.once('data', () => res.destroy(new Error('boom'))); },\n};\n\nawait Sentry.startSpan({ name: 'root' }, async () => {\n for (const [name, handle] of Object.entries(cases)) {\n await new Promise(resolve => {\n const path = `/${name === 'full' ? 'full' : 'slow'}?case=${encodeURIComponent(name)}`;\n const req = http.get({ host: '127.0.0.1', port, path }, res => {\n handle(res);\n res.on('close', () => setTimeout(resolve, 300));\n res.on('error', () => {});\n });\n req.on('error', () => {});\n });\n }\n});\n\nawait Sentry.flush(2000);\nfor (const name of Object.keys(cases)) {\n const path = `/${name === 'full' ? 'full' : 'slow'}?case=${encodeURIComponent(name)}`;\n const url = `http://127.0.0.1:${port}${path}`;\n console.log(\n name.padEnd(26),\n '| spanEnd fired:', ended.has(url) ? `yes (status=${ended.get(url)})` : 'NO',\n '| span in envelope:', sentSpans.has(url) ? `yes (status=${sentSpans.get(url)})` : 'NO',\n );\n}\nsrv.closeAllConnections();\nsrv.close();\nsink.close();\nsetTimeout(() => process.exit(0), 100);\n```\n\n### Steps to Reproduce\n\n1. `npm i @sentry/node@11.8.0`\n2. Save the script above as `repro.mjs` and run `node repro.mjs`.\n3. Look at the three `http.client` spans: one for a fully read response, one where the client calls\n `res.destroy()` after the first chunk, and one where it calls `res.destroy(new Error('boom'))`.\n\n### Expected Result\n\nAll three `http.client` spans end. A response that was cut off before the end should end the span\nwith an error status (the code already does this for an aborted response, see `response.aborted`\nin `finishWithResponse`).\n\n### Actual Result\n\n```\nfull | spanEnd fired: yes (status=ok) | span in envelope: yes (status=ok)\nres.destroy() | spanEnd fired: NO | span in envelope: NO\nres.destroy(new Error()) | spanEnd fired: yes (status=error) | span in envelope: yes (status=error)\n```\n\nWith `res.destroy()` the span never ends, so it is never sent.\n\nI also checked the other ways to cut a request short after the response headers arrived. These\nall end the span correctly: `req.destroy()` (error), `req.destroy(new Error())` (error),\n`AbortController.abort()` on `http.request` after the headers (ok, per #25260), and abort before\nthe response (ok).\n\n### Additional Context\n\nCause, in `packages/core/src/integrations/http/client-subscriptions.ts` on `develop`:\n\n- L143: the request `close` fallback (`requestOnClose`) is what ends the span if there is no response.\n- L168: as soon as a response arrives, that fallback is removed (`request.removeListener('close', requestOnClose)`),\n because the span should now end with the response.\n- L197-198: the only things that can end it after that are `response.on('end', ...)` and\n `response.on(errorMonitor, ...)`.\n\n`res.destroy()` without an argument emits neither `end` nor `error` on the response, only `close`\n(and `aborted`). So nothing is left that ends the span. With `res.destroy(err)` the response emits\n`error`, which is why that case works. The `aborted` check at L187 is only reached through those\ntwo listeners, so it never sees this case.\n\nThis is the same kind of gap that #25260 (http client, abort is not an error) and #25129 (fetch) fixed\nfor aborts by the caller, but those only change the status of spans that already end. I could not find\nan existing issue or PR for the span not ending at all. I searched open and closed issues and PRs for\nhttp client span, destroy, aborted and leak. The closest are #25183 and #25209, which are the same\nsymptom for the Express request-handler span.\n\nA fix would be to also end the span on the response `close` event (a no-op if `end` or `error` already\nfired), with an error status when the response is incomplete. I have a patch with tests and can open a PR\nif that direction is fine.\n","author":{"url":"https://github.com/4ktLuffy","@type":"Person","name":"4ktLuffy"},"datePublished":"2026-10-16T20:48:00Z","url":"https://github.com/getsentry/sentry-javascript/issues/25469"}
| 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:d27dd2d6-6025-be4b-3dca-a73e90cdb2a5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 97FE:237D74:43AD2:5AFC2:6B042A8E |
| html-safe-nonce | 2b9a89fb82017a62b217c224fd013bbb42e8ed0065bf0ac5d02ef4c49f3b9d0d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5N0ZFOjIzN0Q3NDo0M0FEMjo1QUZDMjo2QjA0MkE4RSIsInZpc2l0b3JfaWQiOiI0NjE4NTc5NDM0MTQyOTY4NDYyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 96419361b1b0e2fd24c6159ae32afd533a0370d32d734a33d0949dede45bd386 |
| hovercard-subject-tag | issue:5890975551 |
| 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/getsentry/sentry-javascript/25469/issue_layout |
| twitter:image | https://opengraph.githubassets.com/82a68577b4dabe273a2e465c749f07ce55e13b80d28f28a77b0c640469b9a34d/getsentry/sentry-javascript/issues/25469 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/82a68577b4dabe273a2e465c749f07ce55e13b80d28f28a77b0c640469b9a34d/getsentry/sentry-javascript/issues/25469 |
| og:image:alt | Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | 4ktLuffy |
| hostname | github.com |
| expected-hostname | github.com |
| None | b7a1d2b9101496921b08579fbee988d014345aef2f5bd660d1f8c7332d81560e |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-javascript git https://github.com/getsentry/sentry-javascript.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 3328572 |
| octolytics-dimension-repository_nwo | getsentry/sentry-javascript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3328572 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-javascript |
| 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 | c3dd496c3da6ea6b77e69c09279d2b81604654f1 |
| 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