Skip to content

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

Open
runningcode wants to merge 3 commits into
no/sentryruntime-foundationfrom
no/sentryruntime-executor-shutdown
Open

runningcode wants to merge 3 commits into
no/sentryruntime-foundationfrom
no/sentryruntime-executor-shutdown

Conversation

@runningcode

@runningcode runningcode commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

📜 Description

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

// Sentry.init
+ initLogger(options);                         // moved up: the internal services log with it
+ services = LegacyOptionsBridge.buildServices(servicesBuilder, options);   // moved before Scopes
  rootScopes = new Scopes(scope, isolationScope, globalScope, services, "Sentry.init");

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

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

Because InternalServices now exists before initConfigurations, its three executor users switch to that executor too:

// Sentry.initConfigurations(options, services)
- options.getExecutorService().submit(/* delete old profiles */);
+ services.getExecutorService().submit(/* delete old profiles */);
- new BackpressureMonitor(options, scopes);
+ new BackpressureMonitor(options, scopes, services.getExecutorService());
- InitUtil.initializeProfiler(options);
+ InitUtil.initializeProfiler(options, services.getExecutorService());

The old BackpressureMonitor constructor and InitUtil.initializeProfiler(options) stay. Spring still needs the latter, because it creates the profiler bean before Sentry.init.

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 InternalServicesTest 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

@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 dab6ded.

Main concerns: public contract, reach, 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.67.0 (1) release

⚙️ sentry-android Build Distribution Settings

@runningcode
runningcode force-pushed the no/sentryruntime-foundation branch from 4b9b580 to a993645 Compare December 3, 2026 12:24
@runningcode
runningcode force-pushed the no/sentryruntime-executor-shutdown branch from 9b97dd6 to 6f20270 Compare December 3, 2026 12:24
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Dec 3, 2026
@runningcode
runningcode force-pushed the no/sentryruntime-executor-shutdown branch from a4bc0de to e704c78 Compare December 3, 2026 12:51
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Dec 3, 2026
@runningcode
runningcode force-pushed the no/sentryruntime-executor-shutdown branch from e704c78 to b301d9b Compare December 3, 2026 14:51
@github-actions github-actions Bot removed the risk: medium PR risk score: medium label Dec 3, 2026
@runningcode runningcode changed the title ref(core): Let SentryRuntime own the executor shutdown ref(core): Let InternalServices own the executor shutdown Dec 3, 2026
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Dec 3, 2026
runningcode and others added 3 commits December 3, 2026 16:03
Scopes.close now asks InternalServices to shut the executor down instead of
reading it off SentryOptions. The root Scopes gets InternalServices from
Sentry.init and passes it to its forks; a Scopes created through the
public constructor falls back to the internal services on its options.

Sentry.init builds InternalServices 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 <noreply@anthropic.com>
Now that Sentry.init builds InternalServices before initConfigurations, the
old-profile cleanup, the BackpressureMonitor and the JVM continuous
profiler get the executor from it instead of from SentryOptions.

BackpressureMonitor and InitUtil.initializeProfiler gain overloads that
take the executor. The old ones keep reading it off the options, which
Spring still needs because it creates the profiler before Sentry.init.

Part of JAVA-817

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Part of JAVA-817

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@runningcode
runningcode force-pushed the no/sentryruntime-executor-shutdown branch from b301d9b to dab6ded Compare December 3, 2026 15:03
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Dec 3, 2026
@runningcode
runningcode marked this pull request as ready for review December 3, 2026 15:26
@runningcode
runningcode requested review from a team and adinauer as code owners December 3, 2026 15:26
@runningcode
runningcode removed the request for review from a team December 3, 2026 15:26
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Dec 3, 2026

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