From f12658cdcdacb9117e53133145103a7db888b4de Mon Sep 17 00:00:00 2001 From: AJ Heller Date: Mon, 18 Apr 2022 16:30:47 -0700 Subject: [PATCH] Remove unmatched grpc_init from *ChannelFromFd methods (#29434) * Remove unmatched grpc_init from *ChannelFromFd methods These unmatched grpc_init calls were preventing grpc_shutdown from completing, which notably showed up in the only tests we have that exercise these methods: `client_interceptors_end2end_tests.cc`. These inits appear to be unnecessary, so I removed them. But if I've missed some reason they're needed, an alternative is to find the right place to add the corresponding `init_lib.shutdown();` call. I'm not sure where that would be at this point. See b/175634383 * Alternative: init & shutdown before calling any core library --- src/cpp/client/create_channel_posix.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cpp/client/create_channel_posix.cc b/src/cpp/client/create_channel_posix.cc index 87a28054b01..8e02088ac38 100644 --- a/src/cpp/client/create_channel_posix.cc +++ b/src/cpp/client/create_channel_posix.cc @@ -34,7 +34,7 @@ class ChannelArguments; std::shared_ptr CreateInsecureChannelFromFd(const std::string& target, int fd) { - grpc::internal::GrpcLibrary init_lib; + internal::GrpcLibrary init_lib; init_lib.init(); grpc_channel_credentials* creds = grpc_insecure_credentials_create(); auto channel = CreateChannelInternal( @@ -42,6 +42,8 @@ std::shared_ptr CreateInsecureChannelFromFd(const std::string& target, std::vector< std::unique_ptr>()); grpc_channel_credentials_release(creds); + // Channel also initializes gRPC, so we can decrement the init ref count here. + init_lib.shutdown(); return channel; } @@ -57,6 +59,8 @@ std::shared_ptr CreateCustomInsecureChannelFromFd( std::vector< std::unique_ptr>()); grpc_channel_credentials_release(creds); + // Channel also initializes gRPC, so we can decrement the init ref count here. + init_lib.shutdown(); return channel; } @@ -67,7 +71,7 @@ std::shared_ptr CreateCustomInsecureChannelWithInterceptorsFromFd( std::vector< std::unique_ptr> interceptor_creators) { - grpc::internal::GrpcLibrary init_lib; + internal::GrpcLibrary init_lib; init_lib.init(); grpc_channel_args channel_args; args.SetChannelArgs(&channel_args); @@ -76,6 +80,8 @@ std::shared_ptr CreateCustomInsecureChannelWithInterceptorsFromFd( "", grpc_channel_create_from_fd(target.c_str(), fd, creds, &channel_args), std::move(interceptor_creators)); grpc_channel_credentials_release(creds); + // Channel also initializes gRPC, so we can decrement the init ref count here. + init_lib.shutdown(); return channel; }