fix(telemetry): patch Sentry SDK to prevent 3-second exit delay#85
Merged
Conversation
Contributor
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Issue
Other
Bug Fixes 🐛Issue
Other
Documentation 📚
Internal Changes 🔧
Other
🤖 This preview updates automatically when you update the PR. |
Contributor
Codecov Results 📊✅ Patch coverage is 100.00%. Project has 1663 uncovered lines. Files with missing lines (22)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 64.79% 64.79% —%
==========================================
Files 39 39 —
Lines 4723 4723 —
Branches 0 0 —
==========================================
+ Hits 3060 3060 —
- Misses 1663 1663 —
- Partials 0 0 —Generated by Codecov Action |
f1bbf38 to
96d8e7f
Compare
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
The Sentry SDK flush() method blocks process exit for the full timeout duration due to non-unref'd setTimeout calls. This causes a 3-second hang when exiting the CLI even when there's nothing to send. This patch adds .unref() to timers in: - client.js _isClientDoneProcessing() - polling loop timer - promisebuffer.js drain() - timeout timer Also adds early exit check in _isClientDoneProcessing() when nothing is processing. Includes E2E test to verify the fix. Upstream issue: getsentry/sentry-javascript#18996
96d8e7f to
cfae32a
Compare
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the 3-second hang when exiting the CLI caused by the Sentry SDK's
flush(3000)call.Root Cause
The Sentry SDK's internal timers in
@sentry/coredon't call.unref(), which keeps the Node.js event loop alive for the full timeout duration even when there's nothing to send:client.js_isClientDoneProcessing()- polls with 1ms setTimeout in a looppromisebuffer.jsdrain()- uses setTimeout for the timeout valueChanges
@sentry/core@10.36.0: Add.unref()to these timers with browser-safe checks_numProcessing === 0before the first setTimeout, not afterTesting
E2E test compares exit time with telemetry disabled vs enabled, ensuring the enabled case doesn't add significant delay (< 500ms overhead, definitely < 1.5s total vs previous 3s+).
Upstream
Will file issue at getsentry/sentry-javascript after this PR is validated.