Skip to content

OTLP MetricExporter deadlock issue #2802

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

Open
cijothomas opened this issue Mar 14, 2025 · 3 comments
Open

OTLP MetricExporter deadlock issue #2802

cijothomas opened this issue Mar 14, 2025 · 3 comments
Labels
bug Something isn't working M-exporter-otlp

Comments

@cijothomas
Copy link
Member

https://github.com/open-telemetry/opentelemetry-rust/blob/main/opentelemetry-otlp/src/exporter/tonic/metrics.rs#L58

Tonic MetricExporter uses std::Mutex to protect inner client, and the lock is held across await points. This can cause deadlock. The fix would be to use tokio::Mutex, but then shutdown/cleanup cannot be easily done, like already faced by LogExporter. But that is better than having code that deadlocks.

Opening an issue to track fixing this.

@cijothomas cijothomas added M-exporter-otlp bug Something isn't working labels Mar 14, 2025
@cijothomas
Copy link
Member Author

@fraillt
Copy link
Contributor

fraillt commented Mar 18, 2025

I might be missing something, but current code doesn't hold the lock across the await point...
Given that inner is accessed in two places (export and shutdown), I pretty sure that code is correct and it's not possible to deadlock...
What do I miss here?

@cijothomas
Copy link
Member Author

.and_then(|g| match &*g {
Some(client) => Ok(Arc::clone(client)),
_ => Err(OTelSdkError::AlreadyShutdown),
})?;

if the guard is dropped here itself, then yes, this looks correct. (I was incorrectly assuming the lock guard is not dropped until export() method ends..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working M-exporter-otlp
Projects
None yet
Development

No branches or pull requests

2 participants