Skip to content

fix(core): Prevent lost wakeups in batch processors#5756

Merged
adinauer merged 2 commits into
mainfrom
fix/batch-processor-lost-wakeup
Jul 13, 2026
Merged

fix(core): Prevent lost wakeups in batch processors#5756
adinauer merged 2 commits into
mainfrom
fix/batch-processor-lost-wakeup

Conversation

@adinauer

Copy link
Copy Markdown
Member

📜 Description

Use an atomic scheduling state for the logs and metrics batch processors. A producer now claims delayed flush scheduling with compare-and-set, while a completed flush releases that claim before checking whether more events arrived.

This removes the lock and Future lifecycle checks that allowed an event to be queued without a pending flush. Regression tests verify that both processors schedule another flush after the previous flush has run.

💡 Motivation and Context

An event added while a flush was transitioning from an empty queue to resetting its scheduling flag could remain queued indefinitely. The running flush did not observe it, and the producer saw scheduling as already claimed.

Fixes #5739

💚 How did you test it?

  • ./gradlew spotlessApply apiDump
  • ./gradlew :sentry:test --tests 'io.sentry.logger.LoggerBatchProcessorTest' --tests 'io.sentry.metrics.MetricsBatchProcessorTest'

📝 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

None.

adinauer and others added 2 commits July 13, 2026 10:53
Coordinate log and metric flush scheduling through an atomic state transition. This ensures events added while a flush completes always have a pending task instead of relying on the running Future's completion state.

Fixes #5739

Co-Authored-By: Claude <noreply@anthropic.com>
@sentry

sentry Bot commented Jul 13, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

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

⚙️ sentry-android Build Distribution Settings

@github-actions

Copy link
Copy Markdown
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 402.42 ms 487.10 ms 84.68 ms
Size 0 B 0 B 0 B

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
6b019b7 319.84 ms 333.15 ms 13.31 ms
eb95ded 317.51 ms 369.08 ms 51.57 ms
319f256 317.53 ms 370.83 ms 53.29 ms
b3d8889 420.46 ms 453.71 ms 33.26 ms
6b019b7 403.90 ms 546.09 ms 142.19 ms
889ecea 367.58 ms 437.52 ms 69.94 ms
d15471f 303.49 ms 439.08 ms 135.59 ms
d364ace 384.53 ms 453.51 ms 68.98 ms
6ea4329 309.06 ms 353.48 ms 44.42 ms
c8125f3 383.82 ms 441.66 ms 57.84 ms

App size

Revision Plain With Sentry Diff
6b019b7 0 B 0 B 0 B
eb95ded 0 B 0 B 0 B
319f256 1.58 MiB 2.19 MiB 619.79 KiB
b3d8889 1.58 MiB 2.10 MiB 535.07 KiB
6b019b7 0 B 0 B 0 B
889ecea 1.58 MiB 2.11 MiB 539.75 KiB
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
d364ace 1.58 MiB 2.11 MiB 539.75 KiB
6ea4329 1.58 MiB 2.29 MiB 719.82 KiB
c8125f3 1.58 MiB 2.10 MiB 532.32 KiB

@adinauer adinauer marked this pull request as ready for review July 13, 2026 10:04

@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!

@adinauer adinauer merged commit 98106dd into main Jul 13, 2026
72 checks passed
@adinauer adinauer deleted the fix/batch-processor-lost-wakeup branch July 13, 2026 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lost-wakeup race in the Logs/Metrics batch processor can strand queued events past the flush interval

2 participants