Skip to content

fix(server-utils): End Express layer spans when the client aborts - #25209

Open
chargome wants to merge 2 commits into
developfrom
express-span-client-abort
Open

chargome wants to merge 2 commits into
developfrom
express-span-client-abort

Conversation

@chargome

@chargome chargome commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Express layer spans only ended on the response's finish event. When the client aborts, finish never fires, so the request handler span never ended. Static transactions were sent without it and everything under it, and with span streaming its children were orphaned.

Layer spans now also end on close, which is when the http.server span ends, and are marked as cancelled. Work that is still running when the client aborts ends after the transaction has been sent, so it is not part of the static transaction.

Fixes #25183

@chargome chargome self-assigned this Oct 9, 2026
@chargome

chargome commented Oct 9, 2026

Copy link
Copy Markdown
Member Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit dfacd96. Configure here.

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 29.8 kB - -
@sentry/browser - with treeshaking flags 27.92 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 27.84 kB - -
@sentry/browser (incl. Tracing) 51.85 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 51.87 kB - -
@sentry/browser (incl. Tracing, Profiling) 54.8 kB - -
@sentry/browser (incl. Tracing, Replay) 91.58 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 80.45 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 96.29 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 109.27 kB - -
@sentry/browser (incl. Feedback) 47.32 kB - -
@sentry/browser (incl. sendFeedback) 34.84 kB - -
@sentry/browser (incl. FeedbackAsync) 39.95 kB - -
@sentry/browser (incl. Metrics) 30.82 kB - -
@sentry/browser (incl. Logs) 31.11 kB - -
@sentry/browser (incl. Metrics & Logs) 31.75 kB - -
@sentry/react 31.63 kB - -
@sentry/react (incl. Tracing) 54.17 kB - -
@sentry/vue 37.84 kB - -
@sentry/vue (incl. Tracing) 54.78 kB - -
@sentry/svelte 29.83 kB - -
@sentry/remix (Remix 3 client bundle) 56.83 kB - -
CDN Bundle 31.53 kB - -
CDN Bundle (incl. Tracing) 52.34 kB - -
CDN Bundle (incl. Logs, Metrics) 33.72 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 54.3 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 74.65 kB - -
CDN Bundle (incl. Tracing, Replay) 90.01 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 91.96 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 96.17 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 98.15 kB - -
CDN Bundle - uncompressed 92.92 kB - -
CDN Bundle (incl. Tracing) - uncompressed 155.46 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 99.46 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 161.41 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 229.5 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 275.63 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 281.57 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 289.33 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 295.26 kB - -
@sentry/nextjs (client) 56.53 kB - -
@sentry/sveltekit (client) 52.23 kB - -
@sentry/core/server 40.86 kB - -
@sentry/core/browser 13.71 kB - -
@sentry/node 151.03 kB +0.03% +43 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 83.59 kB - -
@sentry/node - without tracing 94.05 kB +0.05% +44 B 🔺
@sentry/node - without channel injection 129.2 kB +0.04% +48 B 🔺
@sentry/aws-serverless 102.21 kB +0.05% +42 B 🔺
@sentry/cloudflare (withSentry) - minified 209.81 kB - -
@sentry/cloudflare (withSentry) 520.23 kB - -
@sentry/nextjs/cloudflare (withSentry) - minified 227.48 kB - -

View base workflow run

chargome and others added 2 commits October 9, 2026 11:57
Express layer spans ended only on the response's finish event. When the
client aborts, finish never fires, so the handler span never ended. Static
transactions were sent without it and its subtree, and with span streaming
its children were orphaned.

Also end the layer span on close, which is when the http.server span ends,
and mark it as cancelled.

Fixes #25183
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bun 1.3.14, the version CI runs, emits no close event on the response when
the client aborts, so the http.server span never ends there. Bun 1.4.0
emits it and the test passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chargome
chargome force-pushed the express-span-client-abort branch from 114ec82 to 8d40ec4 Compare October 9, 2026 09:57
@chargome
chargome marked this pull request as ready for review October 9, 2026 10:18
@chargome
chargome requested a review from a team as a code owner October 9, 2026 10:18
@chargome
chargome requested review from andreiborza, isaacs and mydea and removed request for a team October 9, 2026 10:18

@andreiborza andreiborza left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Express request-handler span never ends when the client aborts, dropping its subtree from the http.server transaction

2 participants