Skip to content

Conversation

Copy link

Copilot AI commented Jan 28, 2026

client.flush(timeout) blocks for the full timeout duration even when _numProcessing === 0, preventing clean process exit in CLI apps and serverless environments.

Changes

Early exit in _isClientDoneProcessing()

  • Check _numProcessing before entering poll loop instead of after first wait
  • Eliminates unnecessary 1ms+ delays when nothing is pending

Unref timers in Node.js environments

  • Add .unref() to setTimeout calls in client.ts and promisebuffer.ts
  • Uses browser-safe check: typeof timer !== 'number' && timer.unref
  • Allows Node.js process to exit naturally when timers are the only pending operations
// Before: always waits at least 1ms
while (!timeout || ticked < timeout) {
  await new Promise(resolve => setTimeout(resolve, 1));
  if (!this._numProcessing) return true;
  ticked++;
}

// After: returns immediately when idle
if (!this._numProcessing) return true;

while (!timeout || ticked < timeout) {
  await new Promise(resolve => {
    const timer = setTimeout(resolve, 1);
    if (typeof timer !== 'number' && timer.unref) timer.unref();
  });
  if (!this._numProcessing) return true;
  ticked++;
}

Impact

  • flush(3000) with no pending work: ~3000ms → <1ms
  • Process exit behavior: blocked by event loop → exits cleanly

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • fastdl.mongodb.org
    • Triggering command: /usr/local/bin/node /usr/local/bin/node ./postinstall.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 28, 2026 15:57
…y exit

Co-authored-by: Lms24 <8420481+Lms24@users.noreply.github.com>
Co-authored-by: Lms24 <8420481+Lms24@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix bug for issue 18996 in sentry-javascript Fix client.flush() blocking process exit due to non-unref'd timers Jan 28, 2026
Copilot AI requested a review from Lms24 January 28, 2026 16:05
@Lms24 Lms24 changed the title Fix client.flush() blocking process exit due to non-unref'd timers fix(core): Avoid blocking the process when calling flush on empty buffer Jan 28, 2026
@github-actions
Copy link
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 25.35 kB +0.09% +21 B 🔺
@sentry/browser - with treeshaking flags 23.86 kB +0.14% +33 B 🔺
@sentry/browser (incl. Tracing) 42.17 kB +0.06% +22 B 🔺
@sentry/browser (incl. Tracing, Profiling) 46.81 kB +0.05% +22 B 🔺
@sentry/browser (incl. Tracing, Replay) 80.8 kB +0.05% +33 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 70.43 kB +0.04% +23 B 🔺
⛔️ @sentry/browser (incl. Tracing, Replay with Canvas) (max: 85.5 kB) 85.5 kB +0.04% +34 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 97.68 kB +0.02% +13 B 🔺
@sentry/browser (incl. Feedback) 42.07 kB +0.06% +23 B 🔺
@sentry/browser (incl. sendFeedback) 30.03 kB +0.06% +16 B 🔺
@sentry/browser (incl. FeedbackAsync) 35.05 kB +0.1% +33 B 🔺
@sentry/browser (incl. Metrics) 26.46 kB +0.11% +29 B 🔺
@sentry/browser (incl. Logs) 26.6 kB +0.09% +23 B 🔺
@sentry/browser (incl. Metrics & Logs) 27.29 kB +0.15% +40 B 🔺
@sentry/react 27.07 kB +0.06% +16 B 🔺
@sentry/react (incl. Tracing) 44.41 kB +0.08% +32 B 🔺
@sentry/vue 29.8 kB +0.11% +32 B 🔺
@sentry/vue (incl. Tracing) 43.97 kB +0.08% +31 B 🔺
@sentry/svelte 25.36 kB +0.08% +20 B 🔺
CDN Bundle 27.93 kB +0.1% +26 B 🔺
CDN Bundle (incl. Tracing) 42.96 kB +0.06% +25 B 🔺
CDN Bundle (incl. Logs, Metrics) 28.77 kB +0.1% +26 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 43.78 kB +0.08% +32 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 67.7 kB +0.04% +23 B 🔺
CDN Bundle (incl. Tracing, Replay) 79.71 kB +0.06% +41 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 80.57 kB +0.04% +29 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 85.15 kB +0.03% +25 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 86.05 kB +0.02% +10 B 🔺
CDN Bundle - uncompressed 81.72 kB +0.14% +109 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 127.27 kB +0.09% +110 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 84.56 kB +0.13% +109 B 🔺
⛔️ CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed (max: 130 kB) 130.1 kB +0.09% +110 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 207.94 kB +0.06% +109 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 243.87 kB +0.05% +110 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 246.69 kB +0.05% +110 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 256.67 kB +0.05% +110 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 259.48 kB +0.05% +110 B 🔺
@sentry/nextjs (client) 46.76 kB +0.08% +34 B 🔺
@sentry/sveltekit (client) 42.54 kB +0.08% +30 B 🔺
@sentry/node-core 52.1 kB +0.05% +23 B 🔺
@sentry/node 166.11 kB +0.03% +34 B 🔺
@sentry/node - without tracing 93.86 kB +0.03% +25 B 🔺
@sentry/aws-serverless 109.39 kB +0.03% +30 B 🔺

View base workflow run

@github-actions
Copy link
Contributor

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 9,225 - 8,974 +3%
GET With Sentry 1,710 19% 1,666 +3%
GET With Sentry (error only) 6,174 67% 6,056 +2%
POST Baseline 1,199 - 1,200 -0%
POST With Sentry 585 49% 586 -0%
POST With Sentry (error only) 1,054 88% 1,062 -1%
MYSQL Baseline 3,331 - 3,314 +1%
MYSQL With Sentry 478 14% 451 +6%
MYSQL With Sentry (error only) 2,709 81% 2,680 +1%

View base workflow run

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