feat(metrics): [Trace Metrics 24] PR Feedback#5013
feat(metrics): [Trace Metrics 24] PR Feedback#5013adinauer merged 1 commit intofeat/trace-metricsfrom
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.
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 |

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