Title: Express request-handler span never ends when the client aborts, dropping its subtree from the http.server transaction · Issue #25183 · getsentry/sentry-javascript · GitHub
Open Graph Title: Express request-handler span never ends when the client aborts, dropping its subtree from the http.server transaction · Issue #25183 · getsentry/sentry-javascript
X Title: Express request-handler span never ends when the client aborts, dropping its subtree from the http.server transaction · Issue #25183 · getsentry/sentry-javascript
Description: Package + version @sentry/react-router 10.55.0 (also reproduced on 11.5.0, both traceLifecycle: "static" and the default "stream"), express 4, Node 22. Description The Express layer patch ends a terminal request_handler layer span only o...
Open Graph Description: Package + version @sentry/react-router 10.55.0 (also reproduced on 11.5.0, both traceLifecycle: "static" and the default "stream"), express 4, Node 22. Description The Express layer patch ends a te...
X Description: Package + version @sentry/react-router 10.55.0 (also reproduced on 11.5.0, both traceLifecycle: "static" and the default "stream"), express 4, Node 22. Description The Express l...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/25183
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Express request-handler span never ends when the client aborts, dropping its subtree from the http.server transaction","articleBody":"### Package + version\n@sentry/react-router 10.55.0 (also reproduced on 11.5.0, both `traceLifecycle: \"static\"` and the default `\"stream\"`), express 4, Node 22.\n\n### Description\nThe Express layer patch ends a terminal `request_handler` layer span only on `res.once(\"finish\")` (10.x: `@sentry/core/.../express/patch-layer.js`; 11.x: `@sentry/server-utils/.../express/instrumentation.js`). The `http.server` root span ends on `response.on(\"close\")`.\n\nWhen the client aborts the request before the response completes, `close` fires but `finish` never does. The handler span is never ended, so:\n\n- **static (10.x and 11.x):** the `http.server` transaction is sent with only the already-ended passthrough middleware spans. The handler span and everything under it are missing (loaders, DB spans).\n- **11.x stream:** the loader/DB spans are sent, but their parent (the handler span) never is, so they are orphaned in the trace view.\n\nThis hits React Router's `createRequestHandler` all the time in production. A superseded client navigation aborts the `.data` fetch, and those are usually the slow requests, which are exactly the ones you want to see.\n\n### Reproduction\n`init.mjs`:\n```js\nimport * as Sentry from \"@sentry/react-router\";\nSentry.init({\n dsn: \"https://public@o0.ingest.sentry.io/0\",\n tracesSampleRate: 1.0,\n tracePropagationTargets: [],\n traceLifecycle: \"static\",\n beforeSendTransaction(event) {\n console.log(\"TXN\", event.transaction, (event.spans ?? []).map((s) => s.op));\n return null;\n },\n});\n```\n`app.cjs`:\n```js\nconst Sentry = require(\"@sentry/react-router\");\nconst express = require(\"express\");\nconst app = express();\napp.use((req, res, next) => next());\napp.use(async (req, res) => {\n await Sentry.startSpan({ name: \"loader\", op: \"function.react_router.loader\" },\n () => new Promise((r) => setTimeout(r, 800)));\n res.end(\"ok\");\n});\nconst server = app.listen(0, async () => {\n const url = `http://127.0.0.1:${server.address().port}/x`;\n await fetch(url);\n await new Promise((r) => setTimeout(r, 300));\n await fetch(url, { signal: AbortSignal.timeout(100) }).catch(() => {});\n await new Promise((r) => setTimeout(r, 2000));\n await Sentry.flush(1000);\n process.exit(0);\n});\n```\n`node --import ./init.mjs app.cjs`\n\n### Expected\nThe aborted request's transaction contains the handler span (ended at `close`, ideally marked cancelled) and its loader child, same as the completed request.\n\n### Actual (3/3 runs)\n```\nTXN GET /x [ 'middleware', 'middleware', 'function.react_router.loader' ] \u003c- completed\nTXN GET /x [ 'middleware' ] \u003c- aborted\n```\n\n### Still present on `develop`\n`packages/server-utils/src/integrations/express/instrumentation.ts:358` only registers `res.once('finish', onFinish)`. #24854 changed when layer spans end on `next()`, but not the abort path.\n\n### Suggested fix\nAlso end the layer span on `res.once(\"close\")`, not only `\"finish\"`.\n","author":{"url":"https://github.com/mlavesther","@type":"Person","name":"mlavesther"},"datePublished":"2026-10-08T12:50:46Z","url":"https://github.com/getsentry/sentry-javascript/issues/25183"}
| 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:0807c093-f147-9790-9998-e20d110ed2e9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B3DA:339D75:9FAC53:DFAD08:6B042FD3 |
| html-safe-nonce | f7ec2ee71e217aa2c2b34762caa8ba2c06aa2cc39cd34e82ae20252b02fedb0e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCM0RBOjMzOUQ3NTo5RkFDNTM6REZBRDA4OjZCMDQyRkQzIiwidmlzaXRvcl9pZCI6Ijk0MzMwMDU3MjM0NDQ5NjA4MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 9269ce0c3a3456a63186202354688324ff5823ddf0344464d98e32126de19de0 |
| hovercard-subject-tag | issue:5762097126 |
| 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/25183/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3634fc7f13071a6e2fc36ad8715f852415fb014d1c665130a1c920d4175979d0/getsentry/sentry-javascript/issues/25183 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3634fc7f13071a6e2fc36ad8715f852415fb014d1c665130a1c920d4175979d0/getsentry/sentry-javascript/issues/25183 |
| og:image:alt | Package + version @sentry/react-router 10.55.0 (also reproduced on 11.5.0, both traceLifecycle: "static" and the default "stream"), express 4, Node 22. Description The Express layer patch ends a te... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mlavesther |
| 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