Skip to content

Comments

fix: Recreate SentryOptions on each init cycle#503

Merged
limbonaut merged 7 commits intomainfrom
limbonaut/recreate-options-on-init
Feb 11, 2026
Merged

fix: Recreate SentryOptions on each init cycle#503
limbonaut merged 7 commits intomainfrom
limbonaut/recreate-options-on-init

Conversation

@limbonaut
Copy link
Collaborator

@limbonaut limbonaut commented Feb 10, 2026

After switching from automatic-init-only to supporting explicit init()/close() cycles, SentryOptions retained its legacy singleton model. The singleton was created once at extension load and never recreated, so calling SentrySDK.close() followed by SentrySDK.init() caused old state to leak into the next session — callbacks, modified options, and event processors all persisted.

Move SentryOptions ownership from a static singleton to SentrySDK, so each init() call creates fresh options loaded from project settings. This prevents runtime values (before_send, event processors, etc.) from leaking across close()/init() cycles.

Key changes:

  • Replace SentryOptions singleton with create_from_project_settings() factory
  • SentrySDK owns options via Ref<SentryOptions> member, exposed through get_options() accessor and SENTRY_OPTIONS() macro
  • SentryExperimental uses a raw owner pointer (with null-safety in destructor) instead of routing through a global accessor
  • Built-in event processor registration moved into init() so processors don't accumulate on repeated cycles

limbonaut and others added 2 commits February 10, 2026 18:14
Move options ownership from a static singleton to SentrySDK. Each call
to init() now creates fresh options via a factory method, preventing
runtime values (before_send, event_processors, etc.) from leaking
across close()/init() cycles.

- Replace SentryOptions singleton with create_from_project_settings()
  factory that returns a new Ref<SentryOptions> loaded from project
  settings
- SentrySDK owns options via Ref<SentryOptions> member with
  get_options() accessor and SENTRY_OPTIONS() convenience macro
- SentryExperimental holds a raw pointer to its owning SentryOptions
  instead of routing through a global accessor
- Move built-in event processor registration into init() so processors
  don't accumulate on repeated init cycles
- SentryOptions constructor only sets code defaults, keeping doc
  generation clean from project settings values

Fixes #501

Co-Authored-By: Claude <[email protected]>
SentryExperimental holds a raw pointer back to its owning
SentryOptions. Since SentryExperimental is RefCounted, it can
outlive the parent if GDScript holds a reference. Clear the
pointer in the destructor so surviving references safely hit
null checks instead of accessing freed memory.

Co-Authored-By: Claude <[email protected]>
@github-actions
Copy link
Contributor

github-actions bot commented Feb 10, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


Bug Fixes 🐛

  • Recreate SentryOptions on each init cycle by limbonaut in #503
  • Recreate SentryOptions on each init cycle by limbonaut in #503
  • Suppress warning about instantiated SentryLogger default value by limbonaut in #505

Internal Changes 🔧

  • (build) Produce iOS xcframework with framework bundle slices by limbonaut in #500
  • (project) Add isolated test runner in tools panel by limbonaut in #491
  • (release) Fix changelog-preview permissions by BYK in #486
  • Enable logs and set screenshot level to info in test project by limbonaut in #506
  • Ship only addons/sentry/ in build artifacts and release zip by limbonaut in #504
  • Use unique entry point by limbonaut in #499
  • Fix usage of non-existant OS.get_memory_info() key by limbonaut in #493
  • Use int64 for context values on native by limbonaut in #492
  • Extract hash funcs and decouple implementation from STL by limbonaut in #490
  • Add more tools in test project by limbonaut in #489
  • Align enable_logs option with other SDKs by limbonaut in #484

Other

  • release: 1.3.2 by limbonaut in 527dcfc5
  • test: iOS end-to-end in CI by limbonaut in #462

🤖 This preview updates automatically when you update the PR.

@limbonaut limbonaut changed the title ref: Recreate SentryOptions on each init cycle fix: Recreate SentryOptions on each init cycle Feb 10, 2026
@limbonaut limbonaut force-pushed the limbonaut/recreate-options-on-init branch from 66bbecc to 0babaef Compare February 10, 2026 18:34
@limbonaut limbonaut marked this pull request as ready for review February 10, 2026 18:36
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

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.

limbonaut and others added 3 commits February 10, 2026 20:30
The SentrySDK constructor runs before `create_singleton()` assigns the
static singleton pointer. Logging calls during platform SDK creation
dereference the null singleton via SENTRY_OPTIONS(), causing a crash.

Move platform-specific SDK backend creation from the constructor to
`prepare_and_auto_initialize()`, which runs after the singleton is set.
The constructor now defaults to DisabledSDK and creates options eagerly.

Co-Authored-By: Claude <[email protected]>
Reset the internal_sdk shared_ptr before setting singleton to nullptr,
so that sentry_close() callbacks can still access SENTRY_OPTIONS()
during shutdown. Previously, the shared_ptr was destroyed during member
destruction after singleton was already null, causing SIGSEGV on exit.

Co-Authored-By: Claude <[email protected]>
SentrySDK is the sole owner of the InternalSDK instance. Change from
shared_ptr to unique_ptr to better express this ownership semantic.
The accessor now returns a raw pointer since callers only use it
transiently.

Co-Authored-By: Claude <[email protected]>
Copy link

@mujacica mujacica left a comment

Choose a reason for hiding this comment

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

LGTM

@limbonaut limbonaut merged commit c2e4927 into main Feb 11, 2026
56 checks passed
@limbonaut limbonaut deleted the limbonaut/recreate-options-on-init branch February 11, 2026 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SentryOptions retains stale values across close/init cycles

3 participants