Skip to content

Commit ab01a27

Browse files
committed
Merge remote-tracking branch 'upstream/master' into xrfc_tp3
2 parents e1e6243 + ae9b216 commit ab01a27

File tree

11 files changed

+73
-7
lines changed

11 files changed

+73
-7
lines changed

bazel/experiments.bzl

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2570,6 +2570,7 @@ grpc_cc_library(
25702570
"event_engine_tcp_socket_utils",
25712571
"event_engine_thread_pool",
25722572
"event_engine_utils",
2573+
"experiments",
25732574
"forkable",
25742575
"init_internally",
25752576
"iomgr_port",

src/core/lib/event_engine/posix_engine/posix_engine.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include "src/core/lib/event_engine/posix_engine/timer.h"
4949
#include "src/core/lib/event_engine/tcp_socket_utils.h"
5050
#include "src/core/lib/event_engine/utils.h"
51+
#include "src/core/lib/experiments/experiments.h"
5152
#include "src/core/util/crash.h"
5253
#include "src/core/util/no_destruct.h"
5354
#include "src/core/util/sync.h"
@@ -361,7 +362,9 @@ PosixEnginePollerManager::~PosixEnginePollerManager() {
361362
}
362363

363364
PosixEventEngine::PosixEventEngine(std::shared_ptr<PosixEventPoller> poller)
364-
: connection_shards_(std::max(2 * gpr_cpu_num_cores(), 1u)),
365+
: grpc_core::KeepsGrpcInitialized(
366+
/*enabled=*/!grpc_core::IsPosixEeSkipGrpcInitEnabled()),
367+
connection_shards_(std::max(2 * gpr_cpu_num_cores(), 1u)),
365368
executor_(MakeThreadPool(grpc_core::Clamp(gpr_cpu_num_cores(), 4u, 16u))),
366369
timer_manager_(std::make_shared<TimerManager>(executor_)) {
367370
g_timer_fork_manager->RegisterForkable(
@@ -374,7 +377,9 @@ PosixEventEngine::PosixEventEngine(std::shared_ptr<PosixEventPoller> poller)
374377
}
375378

376379
PosixEventEngine::PosixEventEngine()
377-
: connection_shards_(std::max(2 * gpr_cpu_num_cores(), 1u)),
380+
: grpc_core::KeepsGrpcInitialized(
381+
/*enabled=*/!grpc_core::IsPosixEeSkipGrpcInitEnabled()),
382+
connection_shards_(std::max(2 * gpr_cpu_num_cores(), 1u)),
378383
executor_(MakeThreadPool(grpc_core::Clamp(gpr_cpu_num_cores(), 4u, 16u))),
379384
timer_manager_(std::make_shared<TimerManager>(executor_)) {
380385
g_timer_fork_manager->RegisterForkable(

src/core/lib/event_engine/posix_engine/posix_engine.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@ class PosixEnginePollerManager
132132

133133
// An iomgr-based Posix EventEngine implementation.
134134
// All methods require an ExecCtx to already exist on the thread's stack.
135-
// TODO(ctiller): KeepsGrpcInitialized is an interim measure to ensure that
136-
// EventEngine is shut down before we shut down iomgr.
137135
class PosixEventEngine final : public PosixEventEngineWithFdSupport,
138136
public grpc_core::KeepsGrpcInitialized {
139137
public:

src/core/lib/event_engine/windows/windows_engine.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "src/core/lib/event_engine/windows/windows_engine.h"
4444
#include "src/core/lib/event_engine/windows/windows_listener.h"
4545
#include "src/core/lib/iomgr/error.h"
46+
#include "src/core/lib/surface/init_internally.h"
4647
#include "src/core/util/crash.h"
4748
#include "src/core/util/dump_args.h"
4849
#include "src/core/util/sync.h"

src/core/lib/experiments/experiments.cc

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/lib/experiments/experiments.h

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/lib/experiments/experiments.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@
132132
expiry: 2025/03/01
133133
owner: roth@google.com
134134
test_tags: ["lb_unit_test", "cpp_lb_end2end_test", "xds_end2end_test"]
135+
- name: posix_ee_skip_grpc_init
136+
description:
137+
Prevent the PosixEventEngine from calling grpc_init & grpc_shutdown on
138+
creation and destruction.
139+
expiry: 2025/03/02
140+
owner: hork@google.com
141+
test_tags: ["core_end2end_test", "cpp_end2end_test"]
135142
- name: prioritize_finished_requests
136143
description: Prioritize flushing out finished requests over other in-flight
137144
requests during transport writes.

src/core/lib/experiments/rollouts.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@
9191
default: true
9292
- name: pick_first_new
9393
default: true
94+
- name: posix_ee_skip_grpc_init
95+
default: false
9496
- name: prioritize_finished_requests
9597
default: false
9698
- name: promise_based_client_call

src/core/lib/surface/init_internally.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,21 @@ extern bool (*IsInitializedInternally)();
2626

2727
class KeepsGrpcInitialized {
2828
public:
29-
KeepsGrpcInitialized() { InitInternally(); }
30-
~KeepsGrpcInitialized() { ShutdownInternally(); }
29+
explicit KeepsGrpcInitialized(bool enabled = true) : enabled_(enabled) {
30+
if (enabled_) {
31+
InitInternally();
32+
}
33+
}
34+
~KeepsGrpcInitialized() {
35+
if (enabled_) {
36+
ShutdownInternally();
37+
}
38+
}
3139
KeepsGrpcInitialized(const KeepsGrpcInitialized&) = delete;
3240
KeepsGrpcInitialized& operator=(const KeepsGrpcInitialized&) = delete;
41+
42+
private:
43+
bool enabled_;
3344
};
3445

3546
} // namespace grpc_core

0 commit comments

Comments
 (0)