[build] Remove dependency cycle for grpc_init/shutdown (#30921)

* [build] Remove dependency cycle for grpc_init/shutdown

* missing files

* Automated change: Fix sanity tests

* fix

* fix

Co-authored-by: ctiller <ctiller@users.noreply.github.com>
pull/30905/head^2
Craig Tiller 2 years ago committed by GitHub
parent 96e09c0747
commit 346c103a1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      BUILD
  2. 2
      CMakeLists.txt
  3. 2
      Makefile
  4. 4
      build_autogenerated.yaml
  5. 1
      config.m4
  6. 1
      config.w32
  7. 2
      gRPC-C++.podspec
  8. 3
      gRPC-Core.podspec
  9. 2
      grpc.gemspec
  10. 2
      grpc.gyp
  11. 2
      package.xml
  12. 6
      src/core/ext/filters/client_channel/subchannel.cc
  13. 5
      src/core/ext/xds/xds_transport_grpc.cc
  14. 5
      src/core/lib/surface/channel.cc
  15. 3
      src/core/lib/surface/init.cc
  16. 24
      src/core/lib/surface/init_internally.cc
  17. 28
      src/core/lib/surface/init_internally.h
  18. 1
      src/python/grpcio/grpc_core_dependencies.py
  19. 2
      tools/doxygen/Doxyfile.c++.internal
  20. 2
      tools/doxygen/Doxyfile.core.internal

12
BUILD

@ -496,6 +496,13 @@ grpc_cc_library(
],
)
grpc_cc_library(
name = "init_internally",
srcs = ["src/core/lib/surface/init_internally.cc"],
hdrs = ["src/core/lib/surface/init_internally.h"],
deps = ["gpr_platform"],
)
grpc_cc_library(
name = "grpc_unsecure",
srcs = [
@ -529,6 +536,7 @@ grpc_cc_library(
"grpc_security_base",
"grpc_trace",
"http_connect_handshaker",
"init_internally",
"iomgr_timer",
"posix_event_engine_timer_manager",
"slice",
@ -610,6 +618,7 @@ grpc_cc_library(
"http_connect_handshaker",
"httpcli",
"httpcli_ssl_credentials",
"init_internally",
"iomgr_timer",
"json",
"posix_event_engine_timer_manager",
@ -3306,6 +3315,7 @@ grpc_cc_library(
"grpc_trace",
"handshaker_registry",
"http2_errors",
"init_internally",
"iomgr_fwd",
"iomgr_port",
"iomgr_timer",
@ -3789,6 +3799,7 @@ grpc_cc_library(
"grpc_service_config_impl",
"grpc_trace",
"http_connect_handshaker",
"init_internally",
"iomgr_fwd",
"iomgr_timer",
"json",
@ -4579,6 +4590,7 @@ grpc_cc_library(
"grpc_tls_credentials",
"grpc_trace",
"grpc_transport_chttp2_client_connector",
"init_internally",
"iomgr_timer",
"json",
"json_util",

2
CMakeLists.txt generated

@ -2313,6 +2313,7 @@ add_library(grpc
src/core/lib/surface/completion_queue_factory.cc
src/core/lib/surface/event_string.cc
src/core/lib/surface/init.cc
src/core/lib/surface/init_internally.cc
src/core/lib/surface/lame_client.cc
src/core/lib/surface/metadata_array.cc
src/core/lib/surface/server.cc
@ -2911,6 +2912,7 @@ add_library(grpc_unsecure
src/core/lib/surface/completion_queue_factory.cc
src/core/lib/surface/event_string.cc
src/core/lib/surface/init.cc
src/core/lib/surface/init_internally.cc
src/core/lib/surface/lame_client.cc
src/core/lib/surface/metadata_array.cc
src/core/lib/surface/server.cc

2
Makefile generated

@ -1602,6 +1602,7 @@ LIBGRPC_SRC = \
src/core/lib/surface/completion_queue_factory.cc \
src/core/lib/surface/event_string.cc \
src/core/lib/surface/init.cc \
src/core/lib/surface/init_internally.cc \
src/core/lib/surface/lame_client.cc \
src/core/lib/surface/metadata_array.cc \
src/core/lib/surface/server.cc \
@ -2064,6 +2065,7 @@ LIBGRPC_UNSECURE_SRC = \
src/core/lib/surface/completion_queue_factory.cc \
src/core/lib/surface/event_string.cc \
src/core/lib/surface/init.cc \
src/core/lib/surface/init_internally.cc \
src/core/lib/surface/lame_client.cc \
src/core/lib/surface/metadata_array.cc \
src/core/lib/surface/server.cc \

@ -999,6 +999,7 @@ libs:
- src/core/lib/surface/completion_queue_factory.h
- src/core/lib/surface/event_string.h
- src/core/lib/surface/init.h
- src/core/lib/surface/init_internally.h
- src/core/lib/surface/lame_client.h
- src/core/lib/surface/server.h
- src/core/lib/surface/validate_metadata.h
@ -1686,6 +1687,7 @@ libs:
- src/core/lib/surface/completion_queue_factory.cc
- src/core/lib/surface/event_string.cc
- src/core/lib/surface/init.cc
- src/core/lib/surface/init_internally.cc
- src/core/lib/surface/lame_client.cc
- src/core/lib/surface/metadata_array.cc
- src/core/lib/surface/server.cc
@ -2191,6 +2193,7 @@ libs:
- src/core/lib/surface/completion_queue_factory.h
- src/core/lib/surface/event_string.h
- src/core/lib/surface/init.h
- src/core/lib/surface/init_internally.h
- src/core/lib/surface/lame_client.h
- src/core/lib/surface/server.h
- src/core/lib/surface/validate_metadata.h
@ -2512,6 +2515,7 @@ libs:
- src/core/lib/surface/completion_queue_factory.cc
- src/core/lib/surface/event_string.cc
- src/core/lib/surface/init.cc
- src/core/lib/surface/init_internally.cc
- src/core/lib/surface/lame_client.cc
- src/core/lib/surface/metadata_array.cc
- src/core/lib/surface/server.cc

1
config.m4 generated

@ -717,6 +717,7 @@ if test "$PHP_GRPC" != "no"; then
src/core/lib/surface/completion_queue_factory.cc \
src/core/lib/surface/event_string.cc \
src/core/lib/surface/init.cc \
src/core/lib/surface/init_internally.cc \
src/core/lib/surface/lame_client.cc \
src/core/lib/surface/metadata_array.cc \
src/core/lib/surface/server.cc \

1
config.w32 generated

@ -683,6 +683,7 @@ if (PHP_GRPC != "no") {
"src\\core\\lib\\surface\\completion_queue_factory.cc " +
"src\\core\\lib\\surface\\event_string.cc " +
"src\\core\\lib\\surface\\init.cc " +
"src\\core\\lib\\surface\\init_internally.cc " +
"src\\core\\lib\\surface\\lame_client.cc " +
"src\\core\\lib\\surface\\metadata_array.cc " +
"src\\core\\lib\\surface\\server.cc " +

2
gRPC-C++.podspec generated

@ -930,6 +930,7 @@ Pod::Spec.new do |s|
'src/core/lib/surface/completion_queue_factory.h',
'src/core/lib/surface/event_string.h',
'src/core/lib/surface/init.h',
'src/core/lib/surface/init_internally.h',
'src/core/lib/surface/lame_client.h',
'src/core/lib/surface/server.h',
'src/core/lib/surface/validate_metadata.h',
@ -1790,6 +1791,7 @@ Pod::Spec.new do |s|
'src/core/lib/surface/completion_queue_factory.h',
'src/core/lib/surface/event_string.h',
'src/core/lib/surface/init.h',
'src/core/lib/surface/init_internally.h',
'src/core/lib/surface/lame_client.h',
'src/core/lib/surface/server.h',
'src/core/lib/surface/validate_metadata.h',

3
gRPC-Core.podspec generated

@ -1545,6 +1545,8 @@ Pod::Spec.new do |s|
'src/core/lib/surface/event_string.h',
'src/core/lib/surface/init.cc',
'src/core/lib/surface/init.h',
'src/core/lib/surface/init_internally.cc',
'src/core/lib/surface/init_internally.h',
'src/core/lib/surface/lame_client.cc',
'src/core/lib/surface/lame_client.h',
'src/core/lib/surface/metadata_array.cc',
@ -2416,6 +2418,7 @@ Pod::Spec.new do |s|
'src/core/lib/surface/completion_queue_factory.h',
'src/core/lib/surface/event_string.h',
'src/core/lib/surface/init.h',
'src/core/lib/surface/init_internally.h',
'src/core/lib/surface/lame_client.h',
'src/core/lib/surface/server.h',
'src/core/lib/surface/validate_metadata.h',

2
grpc.gemspec generated

@ -1458,6 +1458,8 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/surface/event_string.h )
s.files += %w( src/core/lib/surface/init.cc )
s.files += %w( src/core/lib/surface/init.h )
s.files += %w( src/core/lib/surface/init_internally.cc )
s.files += %w( src/core/lib/surface/init_internally.h )
s.files += %w( src/core/lib/surface/lame_client.cc )
s.files += %w( src/core/lib/surface/lame_client.h )
s.files += %w( src/core/lib/surface/metadata_array.cc )

2
grpc.gyp generated

@ -1007,6 +1007,7 @@
'src/core/lib/surface/completion_queue_factory.cc',
'src/core/lib/surface/event_string.cc',
'src/core/lib/surface/init.cc',
'src/core/lib/surface/init_internally.cc',
'src/core/lib/surface/lame_client.cc',
'src/core/lib/surface/metadata_array.cc',
'src/core/lib/surface/server.cc',
@ -1415,6 +1416,7 @@
'src/core/lib/surface/completion_queue_factory.cc',
'src/core/lib/surface/event_string.cc',
'src/core/lib/surface/init.cc',
'src/core/lib/surface/init_internally.cc',
'src/core/lib/surface/lame_client.cc',
'src/core/lib/surface/metadata_array.cc',
'src/core/lib/surface/server.cc',

2
package.xml generated

@ -1440,6 +1440,8 @@
<file baseinstalldir="/" name="src/core/lib/surface/event_string.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/surface/init.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/surface/init.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/surface/init_internally.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/surface/init_internally.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/surface/lame_client.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/surface/lame_client.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/surface/metadata_array.cc" role="src" />

@ -31,7 +31,6 @@
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include <grpc/grpc.h>
#include <grpc/impl/codegen/grpc_types.h>
#include <grpc/slice.h>
#include <grpc/status.h>
@ -62,6 +61,7 @@
#include "src/core/lib/iomgr/pollset_set.h"
#include "src/core/lib/surface/channel_init.h"
#include "src/core/lib/surface/channel_stack_type.h"
#include "src/core/lib/surface/init_internally.h"
#include "src/core/lib/transport/connectivity_state.h"
#include "src/core/lib/transport/error_utils.h"
@ -636,7 +636,7 @@ Subchannel::Subchannel(SubchannelKey key,
// before the last subchannel destruction, then there maybe race conditions
// triggering segmentation faults. To prevent this issue, we call a grpc_init
// here and a grpc_shutdown in the subchannel destructor.
grpc_init();
InitInternally();
GRPC_STATS_INC_CLIENT_SUBCHANNELS_CREATED();
GRPC_CLOSURE_INIT(&on_connecting_finished_, OnConnectingFinished, this,
grpc_schedule_on_exec_ctx);
@ -672,7 +672,7 @@ Subchannel::~Subchannel() {
connector_.reset();
grpc_pollset_set_destroy(pollset_set_);
// grpc_shutdown is called here because grpc_init is called in the ctor.
grpc_shutdown();
ShutdownInternally();
}
RefCountedPtr<Subchannel> Subchannel::Create(

@ -51,6 +51,7 @@
#include "src/core/lib/slice/slice_refcount.h"
#include "src/core/lib/surface/call.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/init_internally.h"
#include "src/core/lib/surface/lame_client.h"
#include "src/core/lib/transport/connectivity_state.h"
@ -327,14 +328,14 @@ GrpcXdsTransportFactory::GrpcXdsTransportFactory(const ChannelArgs& args)
interested_parties_(grpc_pollset_set_create()) {
// Calling grpc_init to ensure gRPC does not shut down until the XdsClient is
// destroyed.
grpc_init();
InitInternally();
}
GrpcXdsTransportFactory::~GrpcXdsTransportFactory() {
grpc_pollset_set_destroy(interested_parties_);
// Calling grpc_shutdown to ensure gRPC does not shut down until the XdsClient
// is destroyed.
grpc_shutdown();
ShutdownInternally();
}
OrphanablePtr<XdsTransportFactory::XdsTransport>

@ -56,6 +56,7 @@
#include "src/core/lib/surface/call.h"
#include "src/core/lib/surface/channel_init.h"
#include "src/core/lib/surface/channel_stack_type.h"
#include "src/core/lib/surface/init_internally.h"
#include "src/core/lib/transport/transport.h"
// IWYU pragma: no_include <type_traits>
@ -92,7 +93,7 @@ Channel::Channel(bool is_client, std::string target,
// accommodate that, we call grpc_init() here and then call
// grpc_shutdown() when the channel is actually destroyed, thus
// ensuring that shutdown is deferred until that point.
grpc_init();
InitInternally();
auto channelz_node = channelz_node_;
*channel_stack_->on_destroy = [channelz_node]() {
if (channelz_node != nullptr) {
@ -100,7 +101,7 @@ Channel::Channel(bool is_client, std::string target,
channelz::ChannelTrace::Severity::Info,
grpc_slice_from_static_string("Channel destroyed"));
}
grpc_shutdown();
ShutdownInternally();
};
}

@ -55,6 +55,7 @@
#include "src/core/lib/surface/api_trace.h"
#include "src/core/lib/surface/channel_init.h"
#include "src/core/lib/surface/channel_stack_type.h"
#include "src/core/lib/surface/init_internally.h"
/* (generated) built in registry of plugins */
extern void grpc_register_built_in_plugins(void);
@ -117,6 +118,8 @@ void RegisterSecurityFilters(CoreConfiguration::Builder* builder) {
} // namespace grpc_core
static void do_basic_init(void) {
grpc_core::InitInternally = grpc_init;
grpc_core::ShutdownInternally = grpc_shutdown;
gpr_log_verbosity_init();
g_init_mu = new grpc_core::Mutex();
g_shutting_down_cv = new grpc_core::CondVar();

@ -0,0 +1,24 @@
// Copyright 2022 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <grpc/support/port_platform.h>
#include "src/core/lib/surface/init_internally.h"
namespace grpc_core {
void (*InitInternally)();
void (*ShutdownInternally)();
} // namespace grpc_core

@ -0,0 +1,28 @@
// Copyright 2022 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef GRPC_CORE_LIB_SURFACE_INIT_INTERNALLY_H
#define GRPC_CORE_LIB_SURFACE_INIT_INTERNALLY_H
namespace grpc_core {
// Function pointers that should be used in preference to grpc_init,
// grpc_shutdown from within core, but otherwise do the same thing.
// Avoids a build dependency cycle between grpc and grpc_base (and friends).
extern void (*InitInternally)();
extern void (*ShutdownInternally)();
} // namespace grpc_core
#endif // GRPC_CORE_LIB_SURFACE_INIT_INTERNALLY_H

@ -692,6 +692,7 @@ CORE_SOURCE_FILES = [
'src/core/lib/surface/completion_queue_factory.cc',
'src/core/lib/surface/event_string.cc',
'src/core/lib/surface/init.cc',
'src/core/lib/surface/init_internally.cc',
'src/core/lib/surface/lame_client.cc',
'src/core/lib/surface/metadata_array.cc',
'src/core/lib/surface/server.cc',

@ -2441,6 +2441,8 @@ src/core/lib/surface/event_string.cc \
src/core/lib/surface/event_string.h \
src/core/lib/surface/init.cc \
src/core/lib/surface/init.h \
src/core/lib/surface/init_internally.cc \
src/core/lib/surface/init_internally.h \
src/core/lib/surface/lame_client.cc \
src/core/lib/surface/lame_client.h \
src/core/lib/surface/metadata_array.cc \

@ -2235,6 +2235,8 @@ src/core/lib/surface/event_string.cc \
src/core/lib/surface/event_string.h \
src/core/lib/surface/init.cc \
src/core/lib/surface/init.h \
src/core/lib/surface/init_internally.cc \
src/core/lib/surface/init_internally.h \
src/core/lib/surface/lame_client.cc \
src/core/lib/surface/lame_client.h \
src/core/lib/surface/metadata_array.cc \

Loading…
Cancel
Save