fix(core): Prevent lost wakeups in batch processors#5756
Merged
Conversation
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>
📲 Install BuildsAndroid
|
Contributor
Performance metrics 🚀
|
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📜 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
Futurelifecycle 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
sendDefaultPIIis enabled.🔮 Next steps
None.