Check poll strategy in core fork handler and log error if unsupported

pull/16434/head
Eric Gribkoff 7 years ago
parent acc020caf7
commit 3d1dacd73d
  1. 6
      src/core/lib/iomgr/fork_posix.cc
  2. 13
      src/python/grpcio/grpc/_cython/_cygrpc/fork_posix.pyx.pxi

@ -58,6 +58,12 @@ void grpc_prefork() {
"environment variable GRPC_ENABLE_FORK_SUPPORT=1");
return;
}
if (strcmp(grpc_get_poll_strategy_name(), "epoll1") != 0 &&
strcmp(grpc_get_poll_strategy_name(), "poll") != 0) {
gpr_log(GPR_ERROR,
"Fork support is only compatible with the epoll1 and poll polling "
"strategies");
}
if (!grpc_core::Fork::BlockExecCtx()) {
gpr_log(GPR_INFO,
"Other threads are currently calling into gRPC, skipping fork() "

@ -23,8 +23,6 @@ _AWAIT_THREADS_TIMEOUT_SECONDS = 5
_TRUE_VALUES = ['yes', 'Yes', 'YES', 'true', 'True', 'TRUE', '1']
_SUPPORTED_POLL_STRATEGIES = ['epoll1', 'poll']
# This flag enables experimental support within gRPC Python for applications
# that will fork() without exec(). When enabled, gRPC Python will attempt to
# pause all of its internally created threads before the fork syscall proceeds.
@ -39,8 +37,6 @@ _GRPC_ENABLE_FORK_SUPPORT = (
os.environ.get('GRPC_ENABLE_FORK_SUPPORT', '0')
.lower() in _TRUE_VALUES)
_GRPC_POLL_STRATEGY = os.environ.get('GRPC_POLL_STRATEGY')
cdef void __prefork() nogil:
with gil:
with _fork_state.fork_in_progress_condition:
@ -84,15 +80,6 @@ cdef void __postfork_child() nogil:
def fork_handlers_and_grpc_init():
grpc_init()
if _GRPC_ENABLE_FORK_SUPPORT:
# TODO(ericgribkoff) epoll1 is default for grpcio distribution (poll is
# default on mac). Decide whether to expose grpc_get_poll_strategy_name()
# from ev_posix.cc to get actual poller.
if (_GRPC_POLL_STRATEGY is not None and
_GRPC_POLL_STRATEGY not in _SUPPORTED_POLL_STRATEGIES):
_LOGGER.error(
'gRPC Python fork support is only compatible with the epoll1 '
'and poll polling strategies')
return
with _fork_state.fork_handler_registered_lock:
if not _fork_state.fork_handler_registered:
pthread_atfork(&__prefork, &__postfork_parent, &__postfork_child)

Loading…
Cancel
Save