Skip to content

fix(bun): Keep diagnostics channel subscriptions alive - #24632

Merged
JPeer264 merged 1 commit into
jp/node-suites-denofrom
jp/node-suites-bun-sdk-fixes
Sep 28, 2026
Merged

JPeer264 merged 1 commit into
jp/node-suites-denofrom
jp/node-suites-bun-sdk-fixes

Conversation

@JPeer264

@JPeer264 JPeer264 commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Bun garbage-collects a diagnostics channel that no code references, and its subscribers with it. Node and Deno keep subscribed channels alive. The channel integrations kept no reference, so on Bun they could silently stop producing spans after the first GC. They now create their channels through wrappers in @sentry/server-utils that keep one.

@sentry/bun uses these integrations, and also httpIntegration from @sentry/node, whose channel subscriptions now go through the same wrappers. diagnosticsChannelGc.test.ts reproduces the GC on Bun.

Running the shared Node integration suites on Bun found this. Also an oxlint rule has been added to prevent any issues in the future regarding this

Part of #23889.

🤖 Generated with Claude Code

@linear-code

linear-code Bot commented Sep 23, 2026

Copy link
Copy Markdown

JS-3515

@JPeer264
JPeer264 added this pull request to stack #24633 September 23, 2026 09:51
@JPeer264
JPeer264 force-pushed the jp/node-suites-bun-sdk-fixes branch 2 times, most recently from 33f7607 to 77ca363 Compare September 23, 2026 10:04
@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 29.24 kB - -
@sentry/browser - with treeshaking flags 27.5 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 27.4 kB - -
@sentry/browser (incl. Tracing) 51.15 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 51.17 kB - -
@sentry/browser (incl. Tracing, Profiling) 54.18 kB - -
@sentry/browser (incl. Tracing, Replay) 90.76 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 79.86 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 95.46 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 108.41 kB - -
@sentry/browser (incl. Feedback) 46.76 kB - -
@sentry/browser (incl. sendFeedback) 34.3 kB - -
@sentry/browser (incl. FeedbackAsync) 39.41 kB - -
@sentry/browser (incl. Metrics) 30.25 kB - -
@sentry/browser (incl. Logs) 30.51 kB - -
@sentry/browser (incl. Metrics & Logs) 31.18 kB - -
@sentry/react 31 kB - -
@sentry/react (incl. Tracing) 53.45 kB - -
@sentry/vue 36.74 kB - -
@sentry/vue (incl. Tracing) 53.7 kB - -
@sentry/svelte 29.26 kB - -
CDN Bundle 30.93 kB - -
CDN Bundle (incl. Tracing) 51.69 kB - -
CDN Bundle (incl. Logs, Metrics) 33.2 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 53.66 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 73.92 kB - -
CDN Bundle (incl. Tracing, Replay) 89.28 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 91.25 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 95.45 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 97.42 kB - -
CDN Bundle - uncompressed 91.4 kB - -
CDN Bundle (incl. Tracing) - uncompressed 153.77 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 97.97 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 159.73 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 227.54 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 273.5 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 279.44 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 287.2 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 293.13 kB - -
@sentry/nextjs (client) 55.77 kB - -
@sentry/sveltekit (client) 51.59 kB - -
@sentry/core/server 39.95 kB - -
@sentry/core/browser 13.63 kB - -
@sentry/node 137.15 kB +0.03% +37 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 82.8 kB - -
@sentry/node - without tracing 90.81 kB +0.1% +89 B 🔺
@sentry/node - without channel injection 115.51 kB +0.02% +12 B 🔺
@sentry/aws-serverless 99.08 kB +0.1% +92 B 🔺
@sentry/cloudflare (withSentry) - minified 206.62 kB - -
@sentry/cloudflare (withSentry) 514.02 kB - -

View base workflow run

@JPeer264
JPeer264 force-pushed the jp/node-suites-bun-sdk-fixes branch from 77ca363 to 72e8bec Compare September 23, 2026 12:21
@JPeer264
JPeer264 force-pushed the jp/node-suites-bun-sdk-fixes branch from 72e8bec to 373d5ab Compare September 23, 2026 12:24
@JPeer264
JPeer264 force-pushed the jp/node-suites-bun-sdk-fixes branch from 373d5ab to 49333f3 Compare September 23, 2026 13:23
@JPeer264
JPeer264 force-pushed the jp/node-suites-bun-sdk-fixes branch 2 times, most recently from 7452887 to 27c4421 Compare September 23, 2026 16:19
@JPeer264
JPeer264 removed this pull request from stack #24633 September 23, 2026 16:19
@JPeer264
JPeer264 added this pull request to stack #24670 September 23, 2026 16:19
@JPeer264 JPeer264 changed the title fix(bun, node): Fix channel GC, http.server spans and fetch spans on Bun fix(bun, node): Keep diagnostics channels alive and create http.server spans on Bun Sep 23, 2026
@JPeer264
JPeer264 force-pushed the jp/node-suites-bun-sdk-fixes branch from 27c4421 to ff5d855 Compare September 23, 2026 16:40
@JPeer264
JPeer264 force-pushed the jp/node-suites-bun-sdk-fixes branch 2 times, most recently from b0e5f06 to 21f68ca Compare September 23, 2026 16:59
@JPeer264
JPeer264 removed this pull request from stack #24670 September 23, 2026 17:26
@JPeer264 JPeer264 changed the title fix(bun, node): Keep diagnostics channels alive and create http.server spans on Bun fix(bun): Keep diagnostics channel subscriptions alive Sep 23, 2026
@JPeer264
JPeer264 added this pull request to stack #24671 September 23, 2026 17:31
@JPeer264
JPeer264 force-pushed the jp/node-suites-bun-sdk-fixes branch from 763a9ee to 0b4a065 Compare September 24, 2026 09:13
@JPeer264
JPeer264 force-pushed the jp/node-suites-bun-sdk-fixes branch 2 times, most recently from b3a3cf2 to ef10728 Compare September 24, 2026 14:05
@JPeer264
JPeer264 force-pushed the jp/node-suites-bun-sdk-fixes branch from 7fae1f6 to 2882826 Compare September 25, 2026 15:49
@JPeer264 JPeer264 self-assigned this Sep 25, 2026
@JPeer264
JPeer264 marked this pull request as ready for review September 25, 2026 15:55
@JPeer264
JPeer264 requested a review from a team as a code owner September 25, 2026 15:55
@JPeer264
JPeer264 requested review from andreiborza, isaacs and mydea and removed request for a team September 25, 2026 15:55
@JPeer264
JPeer264 force-pushed the jp/node-suites-bun-sdk-fixes branch 2 times, most recently from b2d38bb to f0392e0 Compare September 27, 2026 13:47
Comment thread packages/server-utils/src/utils/diagnosticsChannel.ts
@JPeer264
JPeer264 force-pushed the jp/node-suites-bun-sdk-fixes branch 2 times, most recently from 6d127e5 to 8d1438b Compare September 27, 2026 14:57
@JPeer264
JPeer264 force-pushed the jp/node-suites-bun-sdk-fixes branch 2 times, most recently from 0ed13e4 to d5ae9f0 Compare September 28, 2026 08:07
@JPeer264

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 d5ae9f0. Configure here.

@JPeer264
JPeer264 force-pushed the jp/node-suites-bun-sdk-fixes branch from d5ae9f0 to dc8b84d Compare September 28, 2026 08:44
@JPeer264
JPeer264 force-pushed the jp/node-suites-bun-sdk-fixes branch from dc8b84d to 78e269f Compare September 28, 2026 09:19
Bun garbage-collects a diagnostics channel that no code references, together
with its subscribers, so a subscription made at init() could stop receiving
messages after the next GC. Node and Deno keep a subscribed channel alive.
On Bun, the channel wrappers in @sentry/server-utils now keep a reference to
every channel they return, and all channel subscriptions in server-utils and
@sentry/node use them, including Prisma and pino. Other runtimes get the
original node:diagnostics_channel functions.

A no-restricted-imports lint rule in server-utils, node and bun rejects value
imports of node:diagnostics_channel outside the wrappers, so new
integrations use them too.

graphql-tracing-channel, which the GC broke, now runs on Bun.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JPeer264
JPeer264 force-pushed the jp/node-suites-bun-sdk-fixes branch from 78e269f to 984e443 Compare September 28, 2026 09:38
Comment on lines +28 to +32
export const subscribe: typeof nodeDiagnosticsChannel.subscribe = keepChannelsReferenced
? (name, onMessage) => {
channel(name).subscribe(onMessage);
}
: nodeDiagnosticsChannel.subscribe;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: The Bun-specific implementation of subscribe returns undefined, but its type annotation incorrectly claims it matches nodeDiagnosticsChannel.subscribe, which should return a subscription object.
Severity: LOW

Suggested Fix

Modify the Bun-specific implementation of the subscribe function to return the result of channel(name).subscribe(onMessage). This will align the function's behavior with its type annotation and the standard Node.js implementation, ensuring it correctly returns a subscription object.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: packages/server-utils/src/utils/diagnosticsChannel.ts#L28-L32

Potential issue: The `subscribe` function in `diagnosticsChannel.ts` has a conditional
implementation for Bun environments. This implementation does not return a value,
resulting in an `undefined` return. However, the function is typed as `typeof
nodeDiagnosticsChannel.subscribe`, which implies it should return a subscription object
with an `unsubscribe()` method. While no current call sites in the codebase utilize this
return value, this type discrepancy could lead to runtime errors in the future if the
function is used in a context that expects a subscription object to be returned.

@JPeer264
JPeer264 merged commit e417276 into develop Sep 28, 2026
496 of 500 checks passed
@JPeer264
JPeer264 deleted the jp/node-suites-bun-sdk-fixes branch September 28, 2026 10:00
andreiborza added a commit that referenced this pull request Sep 28, 2026
…ntegration (#24797)

## What

The MCP server integration now uses the shared diagnostics channel
wrappers, so its subscription stays alive on Bun.

## Why

#24529 and #24632 merged at the same time, and the direct
`node:diagnostics_channel` import now fails lint on `develop` and on the
11.1.0 release PR.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants