Skip to content

[gRPC Exporter] gRPC channel is not properly closed #4429

Open
@XuanWang-Amos

Description

Describe your environment

N/A

What happened?

The gRPC channel is not being closed properly, preventing gRPC from shutting down cleanly.

Steps to Reproduce

Please refer to: grpc/grpc#38490 (comment)

Expected Result

gRPC cleanly shutting down.

Actual Result

gRPC not cleanly shutting down.

Additional context

In OTLPExporterMixin, gRPC channel was created directly and passed to _client:

if insecure:
self._client = self._stub(
insecure_channel(self._endpoint, compression=compression)
)
else:
credentials = _get_credentials(
credentials,
OTEL_EXPORTER_OTLP_CERTIFICATE,
OTEL_EXPORTER_OTLP_CLIENT_KEY,
OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE,
)
self._client = self._stub(
secure_channel(
self._endpoint, credentials, compression=compression
)
)

But the channel was not shutdown in shutdown method:

def shutdown(self, timeout_millis: float = 30_000, **kwargs) -> None:
if self._shutdown:
logger.warning("Exporter already shutdown, ignoring call")
return
# wait for the last export if any
self._export_lock.acquire(timeout=timeout_millis / 1e3)
self._shutdown = True
self._export_lock.release()

gRPC channel should be closed explicitly with context manager or by calling channel.close() method, example usage:
https://github.com/grpc/grpc/blob/822f9b15191840228d17dc0d305887374150150e/examples/python/helloworld/greeter_client.py#L25-L33

If not explicitly closed, the gRPC channel may prevent gRPC from shutting down cleanly, leading to issues like the one described in: grpc/grpc#38490

Would you like to implement a fix?

None

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions