Skip to content

Commit ee7e730

Browse files
committed
Fix oltp exporter shutdown race condition
Exports can start after the lock is acquired but before the shutdown flag is set, this raises an error if the channel has already been closed. Avoid this race condition by setting the shutdown flag before acquiring the lock.
1 parent 534cd38 commit ee7e730

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
([#4475](https://github.com/open-telemetry/opentelemetry-python/pull/4475))
1212
- Improve performance of baggage operations
1313
([#4466](https://github.com/open-telemetry/opentelemetry-python/pull/4466))
14+
- opentelemetry-exporter-otlp-proto-grpc: fix shutdown race condition
15+
([#4490](https://github.com/open-telemetry/opentelemetry-python/pull/4490))
1416

1517
## Version 1.31.0/0.52b0 (2025-03-12)
1618

exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,10 @@ def shutdown(self, timeout_millis: float = 30_000, **kwargs) -> None:
356356
if self._shutdown:
357357
logger.warning("Exporter already shutdown, ignoring call")
358358
return
359+
# set shutdown flag to prevent new exports
360+
self._shutdown = True
359361
# wait for the last export if any
360362
self._export_lock.acquire(timeout=timeout_millis / 1e3)
361-
self._shutdown = True
362363
self._channel.close()
363364
self._export_lock.release()
364365

0 commit comments

Comments
 (0)