Skip to content

ref(core): Let SentryRuntime own the executor shutdown - #6831

Draft
runningcode wants to merge 1 commit into
no/sentryruntime-foundationfrom
no/sentryruntime-executor-shutdown
Draft

runningcode wants to merge 1 commit into
no/sentryruntime-foundationfrom
no/sentryruntime-executor-shutdown

Conversation

@runningcode

Copy link
Copy Markdown
Contributor

📜 Description

Scopes.close now hands the executor shutdown to SentryRuntime.close instead of reading the executor off SentryOptions. The root Scopes gets the runtime from Sentry.init and passes it to its forks.

// Sentry.init
+ initLogger(options);                         // moved up: the runtime logs with it
+ runtime = LegacyOptionsBridge.buildRuntime(runtimeBuilder, options);   // moved before Scopes
  rootScopes = new Scopes(scope, isolationScope, globalScope, runtime, "Sentry.init");

// Scopes.close(isRestarting)
- executor = options.getExecutorService();
- if (isRestarting) executor.submit(() -> executor.close(timeout)); else executor.close(timeout);
+ (runtime != null ? runtime : LegacyOptionsBridge.runtimeOf(options))
+     .close(isRestarting, timeout, logger);

A Scopes created through the public constructor has no runtime, so it falls back to the collaborators on its options and closes as before.

One behavior change: a closed executor passed to init, when options are reused after Sentry.close(), is now replaced before initConfigurations uses it. Before, the old-profile cleanup ran on the closed executor and logged "Old profiles will not be deleted". SentryTest covers it.

💡 Motivation and Context

Part of JAVA-817. Stacked on #6830.

💚 How did you test it?

New SentryRuntimeTest cases for close, and the updated SentryTest case.

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.

🔮 Next steps

Retarget to main once #6830 merges.

🤖 Generated with Claude Code

#skip-changelog

Scopes.close now asks the runtime to shut the executor down instead of
reading it off SentryOptions. The root Scopes gets the runtime from
Sentry.init and passes it to its forks; a Scopes created through the
public constructor falls back to the collaborators on its options.

Sentry.init builds the runtime before the Scopes, so a closed executor
from a previous init is now replaced before anything uses it.

Part of JAVA-817

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@linear-code

linear-code Bot commented Dec 1, 2026

Copy link
Copy Markdown

JAVA-817

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

PR risk: medium

For commit 9b97dd6.

Main concerns: reach, public contract, host performance.

Rules that block low also fired:

  • R4: a public API record changed: sentry/api/sentry.api

This label is a hint for reviewers, not an approval.

@sentry

sentry Bot commented Dec 1, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.66.0 (1) release

⚙️ sentry-android Build Distribution Settings

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant