-
-
Notifications
You must be signed in to change notification settings - Fork 465
feat(metrics): [Trace Metrics 24] PR Feedback #5013
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(metrics): [Trace Metrics 24] PR Feedback #5013
Conversation
Instructions and example for changelogPlease add an entry to Example: ## Unreleased
### Features
- [Trace Metrics 24] PR Feedback ([#5013](https://github.com/getsentry/sentry-java/pull/5013))If none of the above apply, you can opt out of this check by adding |
Performance metrics 🚀
|
| if (isShuttingDown) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: A race condition in MetricsBatchProcessor.close(false) can cause metrics to be silently dropped during shutdown if a metric is added after the final flush has completed.
Severity: HIGH
Suggested Fix
To fix this, consider synchronizing the check for isShuttingDown and the addition to the queue within the add method. Alternatively, the shutdown logic could be revised to ensure that any items added to the queue after the executor is closed are still flushed, potentially by re-checking the queue in a synchronized block after the initial flush loop in close completes.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: sentry/src/main/java/io/sentry/metrics/MetricsBatchProcessor.java#L55-L57
Potential issue: A race condition exists in the `close(false)` method of
`MetricsBatchProcessor`. A metric-producing thread can pass the initial `isShuttingDown`
check just before a separate shutdown thread sets the flag to true, closes the executor,
and drains the queue. If the metric-producing thread then adds its metric to the queue,
the metric will be stranded. The subsequent call to `maybeSchedule` will fail with a
`RejectedExecutionException` because the executor is closed, leading to silent metric
loss and an inconsistent `pendingCount`.
Did we get this right? 👍 / 👎 to inform future reviews.
|
cursor review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Bugbot reviewed your changes and found no bugs!

📜 Description
💡 Motivation and Context
💚 How did you test it?
📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps