fix: Bugsnag network connections even with errors reporting disabled#3190
fix: Bugsnag network connections even with errors reporting disabled#3190jeanfbrito merged 2 commits intodevfrom
Conversation
WalkthroughDisables Bugsnag automatic session tracking ( Changes
Sequence Diagram(s)sequenceDiagram
participant App as App
participant Store as Store (settings)
participant Bugsnag as Bugsnag SDK
participant Server as Bugsnag Endpoint
App->>Store: read reportingEnabled
App->>Bugsnag: start(apiKey, autoTrackSessions: false)
Note right of Bugsnag: Automatic session pings disabled
Store-->>App: emit SETTINGS_CHANGED (toggle reporting)
App->>Bugsnag: manual/queued session trigger (batched after interval)
Bugsnag->>Server: POST /sessions
Bugsnag->>Server: POST /notify (on errors)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/errors/main.spec.ts`:
- Around line 83-101: The tests currently reassign process.env via the
originalEnv constant and directly set/delete keys inside the
beforeEach/afterEach blocks (see beforeEach, afterEach, and originalEnv in
src/errors/main.spec.ts); change this to use Object.defineProperty to mock
specific environment variables (e.g., BUGSNAG_API_KEY and NODE_ENV) and restore
them after each test, and factor the behavior into a small helper (e.g.,
setEnvKey/restoreEnvKey) used by beforeEach/afterEach so you don't reassign
process.env or delete keys directly.
Linux installer download |
Windows installer download |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/errors/main.spec.ts`:
- Line 151: Remove the stray blank line in src/errors/main.spec.ts that was
introduced inside the test file (it's an extra empty line within the test
suite/describe block); open main.spec.ts, locate the empty line around the
failing test area (inside the describe/it test group) and delete that single
blank line so the file has no unintended extra whitespace.
🧹 Nitpick comments (1)
src/errors/main.spec.ts (1)
14-14: Import the action type constant to prevent test drift.The hardcoded string
'settings/set-bugsnag-opt-in-changed'should be imported asSETTINGS_SET_REPORT_OPT_IN_CHANGEDfromsrc/ui/actions, matching how the main process file (src/errors.ts) and other parts of the codebase already use this constant. This prevents silent sync failures if the action type is ever refactored.
83af858 to
3381fb3
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/errors/main.spec.ts`:
- Around line 171-181: The test currently only asserts tracker.sessionCalls ===
0 but should also assert that no notify/network error reports were sent; update
the test that uses interceptBugsnagCalls() and
setupRendererErrorHandling('main') to also assert tracker.notifyCalls (or the
notify counter provided by interceptBugsnagCalls) is 0 after
wait(SHORT_WAIT_MS). Locate the test block containing
unsetEnvVar('BUGSNAG_API_KEY'), createMocks(true), const tracker =
interceptBugsnagCalls(); and add a second expectation verifying no notify calls
were made (e.g., expect(tracker.notifyCalls).toBe(0)).
macOS installer download |
…k connections Adds autoTrackSessions: false to Bugsnag.start() configuration to prevent the SDK from automatically connecting to sessions.bugsnag.com on initialization. This fixes issues in air-gapped networks where the connection attempt triggers certificate error dialogs even when telemetry is disabled. Also upgrades @bugsnag/js from v7.22.3 to v8.8.1.
- Use nock to intercept real HTTP requests from Bugsnag SDK - Verify no network calls when reporting is disabled - Verify sessions are sent when reporting is enabled - Use Object.defineProperty for env var mocking - Skip tests on Windows due to Jest module mocking issues
3381fb3 to
739383b
Compare
Bugsnag SDK was making network requests to
sessions.bugsnag.comeven when error reporting was disabled, causing certificate error dialogs in air-gapped networks. This fix addsautoTrackSessions: falseto the Bugsnag configuration and includes integration tests that verify no network calls occur when reporting is disabled.Root Cause Analysis
The Problem
Users in air-gapped or restricted network environments reported certificate error dialogs appearing on application startup, even with telemetry/error reporting disabled in settings. The dialogs referenced
sessions.bugsnag.com.Whys
Why did certificate error dialogs appear?
→ Because the application attempted HTTPS connections to
sessions.bugsnag.comWhy was the application connecting to sessions.bugsnag.com?
→ Because Bugsnag SDK automatically tracks sessions when
Bugsnag.start()is calledWhy was Bugsnag starting session tracking when reporting was disabled?
→ Because
autoTrackSessionsdefaults totruein the Bugsnag SDK, it starts reporting even if never being started by the codeRoot Cause
The Bugsnag SDK's default configuration (
autoTrackSessions: true) initiates automatic session tracking that makes network requests regardless of the application's reporting preference state.The Fix
Approach
Add
autoTrackSessions: falseto the Bugsnag configuration, then explicitly callstartSession()only when the user has enabled error reporting. This gives the application full control over when session data is transmitted.Why not just avoid calling
Bugsnag.start()when disabled?The current architecture already does this, but the fix provides defense-in-depth: even if
Bugsnag.start()is called, no automatic network requests will occur without an explicitstartSession()call.Implementation
src/errors.ts:97-105- AddedautoTrackSessions: falseto Bugsnag configuration:The existing flow at
src/errors.ts:123-126already callsstartSession()only whenisReportEnabledis true:Files Changed
src/errors.tsautoTrackSessions: falseto Bugsnag configsrc/errors/main.spec.tspackage.jsonnockdev dependency for HTTP mockingVerification
Integration Tests
Created
src/errors/main.spec.tswith 6 tests that usenockto intercept real HTTP requests from the Bugsnag SDK:isReportEnabled: falseBUGSNAG_API_KEYRunning Tests
Note: Tests take ~30 seconds due to Bugsnag's 10-second session batching interval.
Manual Verification
*.bugsnag.comReferences
Summary by CodeRabbit
Chores
Tests