Skip to content

Commit d63bc56

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 d63bc56

File tree

1 file changed

+2
-1
lines changed
  • exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc

1 file changed

+2
-1
lines changed

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

+2-1
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)