Skip to content

fix(core): Report no-op executor tasks as cancelled - #5874

Merged
runningcode merged 5 commits into
mainfrom
no/noop-executor-cancelled-future
Jul 30, 2026
Merged

fix(core): Report no-op executor tasks as cancelled#5874
runningcode merged 5 commits into
mainfrom
no/noop-executor-cancelled-future

Conversation

@runningcode

@runningcode runningcode commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

📜 Description

NoOpSentryExecutorService returned new FutureTask<>(() -> null) from submit/schedule — a task that is never run and never cancelled. Callers had no way to distinguish it from a genuinely queued task: isCancelled() and isDone() both stay false forever, and get() blocks until its timeout.

It now returns an already-cancelled Future, matching what SentryExecutorService already does when its work queue is full. CancelledFuture moves out of SentryExecutorService into a shared package-private class, and ISentryExecutorService documents the requirement so future implementations honour it.

No public API change — CancelledFuture is package-private and no existing signature changed shape, so .api files are untouched.

💡 Motivation and Context

Found by cursor here. That PR's PersistingScopeObserver uses future.isCancelled() to detect a flush task the executor dropped, and releases its hasPendingFlush latch when it sees one. Against a no-op executor the latch would be set with no task to ever clear it, silently stopping scope persistence for the rest of the process.

That is not a reachable bug today because the observer is only installed after options.activate() has swapped in a real executor so this more to prevent regressions in the future. But setExecutorService is public, and the contract the caller relies on was never written down anywhere. Fixing it here, off main, keeps #5791 focused and makes the guarantee available to any other caller that wants to check whether its task was accepted.

💚 How did you test it?

Tests pass

📝 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.

🔮 Next steps

#5791 builds on this guarantee for its scope-write batching.

runningcode and others added 2 commits July 30, 2026 13:40
NoOpSentryExecutorService returned a FutureTask that is never run and
never cancelled, so a caller had no way to tell a dropped task from a
queued one: isCancelled() and isDone() both stay false forever, and get()
blocks until it times out.

Return an already-cancelled Future instead, matching what
SentryExecutorService already does when its work queue is full, and state
the requirement on ISentryExecutorService so future implementations honour
it. CancelledFuture moves out of SentryExecutorService so both services
share one implementation.

An ActivityLifecycleIntegration test asserted a freshly scheduled ttfd
timeout was not cancelled while running on the no-op executor, so it was
really pinning the old pending-forever behaviour rather than the
scheduling it names. It now uses DeferredExecutorService, which queues.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@sentry

sentry Bot commented Jul 30, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

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

⚙️ sentry-android Build Distribution Settings

@runningcode
runningcode marked this pull request as ready for review July 30, 2026 11:46
@runningcode runningcode added the sanity-check PR needs a lightweight review for obvious issues label Jul 30, 2026
Comment thread sentry/src/main/java/io/sentry/NoOpSentryExecutorService.java

@markushi markushi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@0xadam-brown 0xadam-brown left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice! A few optional nits; otherwise lgtm pending fix of the SentryBot issue.

Comment thread sentry/src/main/java/io/sentry/ISentryExecutorService.java Outdated
Comment thread sentry/src/main/java/io/sentry/ISentryExecutorService.java Outdated
Comment thread CHANGELOG.md Outdated
runningcode and others added 2 commits July 30, 2026 14:44
Co-authored-by: arb <adam.brown@sentry.io>
@runningcode
runningcode enabled auto-merge (squash) July 30, 2026 12:46
@github-actions

github-actions Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 315.35 ms 356.68 ms 41.33 ms
Size 0 B 0 B 0 B

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
6b019b7 343.31 ms 417.23 ms 73.91 ms
d15471f 342.08 ms 415.44 ms 73.35 ms
8687935 332.52 ms 362.23 ms 29.71 ms
5b1a06b 352.27 ms 413.70 ms 61.43 ms
91bb874 314.47 ms 440.00 ms 125.53 ms
0ee65e9 321.06 ms 361.24 ms 40.18 ms
e63ad34 323.67 ms 390.33 ms 66.67 ms
33a08cc 267.08 ms 340.45 ms 73.37 ms
27d7cf8 397.90 ms 498.65 ms 100.75 ms
ee747ae 405.43 ms 485.70 ms 80.28 ms

App size

Revision Plain With Sentry Diff
6b019b7 0 B 0 B 0 B
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
8687935 1.58 MiB 2.19 MiB 619.17 KiB
5b1a06b 0 B 0 B 0 B
91bb874 1.58 MiB 2.13 MiB 559.07 KiB
0ee65e9 0 B 0 B 0 B
e63ad34 0 B 0 B 0 B
33a08cc 1.58 MiB 2.12 MiB 555.28 KiB
27d7cf8 1.58 MiB 2.12 MiB 549.42 KiB
ee747ae 1.58 MiB 2.10 MiB 530.95 KiB

Previous results on branch: no/noop-executor-cancelled-future

Startup times

Revision Plain With Sentry Diff
10f8766 325.02 ms 358.47 ms 33.45 ms

App size

Revision Plain With Sentry Diff
10f8766 0 B 0 B 0 B

@runningcode
runningcode merged commit ba5f1d5 into main Jul 30, 2026
71 checks passed
@runningcode
runningcode deleted the no/noop-executor-cancelled-future branch July 30, 2026 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sanity-check PR needs a lightweight review for obvious issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants