Merge pull request #5766 from yang-g/nuke_duplicate_target
Remove end2end_certs library.
diff --git a/Makefile b/Makefile
index eb85c04..6aebadb 100644
--- a/Makefile
+++ b/Makefile
@@ -95,6 +95,46 @@
CPPFLAGS_opt = -O2
DEFINES_opt = NDEBUG
+VALID_CONFIG_dbg = 1
+CC_dbg = $(DEFAULT_CC)
+CXX_dbg = $(DEFAULT_CXX)
+LD_dbg = $(DEFAULT_CC)
+LDXX_dbg = $(DEFAULT_CXX)
+CPPFLAGS_dbg = -O0
+DEFINES_dbg = _DEBUG DEBUG
+
+VALID_CONFIG_easan = 1
+REQUIRE_CUSTOM_LIBRARIES_easan = 1
+CC_easan = clang
+CXX_easan = clang++
+LD_easan = clang
+LDXX_easan = clang++
+CPPFLAGS_easan = -O0 -fsanitize=address -fno-omit-frame-pointer -Wno-unused-command-line-argument -DGPR_NO_DIRECT_SYSCALLS
+LDFLAGS_easan = -fsanitize=address
+DEFINES_easan = _DEBUG DEBUG GRPC_EXECUTION_CONTEXT_SANITIZER
+DEFINES_easan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=3
+
+VALID_CONFIG_asan = 1
+REQUIRE_CUSTOM_LIBRARIES_asan = 1
+CC_asan = clang
+CXX_asan = clang++
+LD_asan = clang
+LDXX_asan = clang++
+CPPFLAGS_asan = -O0 -fsanitize=address -fno-omit-frame-pointer -Wno-unused-command-line-argument -DGPR_NO_DIRECT_SYSCALLS
+LDFLAGS_asan = -fsanitize=address
+DEFINES_asan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=3
+
+VALID_CONFIG_msan = 1
+REQUIRE_CUSTOM_LIBRARIES_msan = 1
+CC_msan = clang
+CXX_msan = clang++
+LD_msan = clang
+LDXX_msan = clang++
+CPPFLAGS_msan = -O0 -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1 -Wno-unused-command-line-argument -fPIE -pie -DGPR_NO_DIRECT_SYSCALLS
+LDFLAGS_msan = -fsanitize=memory -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1 -fPIE -pie $(if $(JENKINS_BUILD),-Wl$(comma)-Ttext-segment=0x7e0000000000,)
+DEFINES_msan = NDEBUG
+DEFINES_msan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=4
+
VALID_CONFIG_basicprof = 1
CC_basicprof = $(DEFAULT_CC)
CXX_basicprof = $(DEFAULT_CXX)
@@ -123,6 +163,14 @@
LDFLAGS_asan-noleaks = -fsanitize=address
DEFINES_asan-noleaks += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=3
+VALID_CONFIG_edbg = 1
+CC_edbg = $(DEFAULT_CC)
+CXX_edbg = $(DEFAULT_CXX)
+LD_edbg = $(DEFAULT_CC)
+LDXX_edbg = $(DEFAULT_CXX)
+CPPFLAGS_edbg = -O0
+DEFINES_edbg = _DEBUG DEBUG GRPC_EXECUTION_CONTEXT_SANITIZER
+
VALID_CONFIG_ubsan = 1
REQUIRE_CUSTOM_LIBRARIES_ubsan = 1
CC_ubsan = clang
@@ -134,13 +182,15 @@
DEFINES_ubsan = NDEBUG
DEFINES_ubsan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=1.5
-VALID_CONFIG_dbg = 1
-CC_dbg = $(DEFAULT_CC)
-CXX_dbg = $(DEFAULT_CXX)
-LD_dbg = $(DEFAULT_CC)
-LDXX_dbg = $(DEFAULT_CXX)
-CPPFLAGS_dbg = -O0
-DEFINES_dbg = _DEBUG DEBUG
+VALID_CONFIG_tsan = 1
+REQUIRE_CUSTOM_LIBRARIES_tsan = 1
+CC_tsan = clang
+CXX_tsan = clang++
+LD_tsan = clang
+LDXX_tsan = clang++
+CPPFLAGS_tsan = -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-unused-command-line-argument -fPIE -pie -DGPR_NO_DIRECT_SYSCALLS
+LDFLAGS_tsan = -fsanitize=thread -fPIE -pie $(if $(JENKINS_BUILD),-Wl$(comma)-Ttext-segment=0x7e0000000000,)
+DEFINES_tsan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=5
VALID_CONFIG_stapprof = 1
CC_stapprof = $(DEFAULT_CC)
@@ -150,14 +200,14 @@
CPPFLAGS_stapprof = -O2 -DGRPC_STAP_PROFILER
DEFINES_stapprof = NDEBUG
-VALID_CONFIG_gcov = 1
-CC_gcov = gcc
-CXX_gcov = g++
-LD_gcov = gcc
-LDXX_gcov = g++
-CPPFLAGS_gcov = -O0 -fprofile-arcs -ftest-coverage -Wno-return-type
-LDFLAGS_gcov = -fprofile-arcs -ftest-coverage -rdynamic
-DEFINES_gcov = _DEBUG DEBUG GPR_GCOV
+VALID_CONFIG_mutrace = 1
+CC_mutrace = $(DEFAULT_CC)
+CXX_mutrace = $(DEFAULT_CXX)
+LD_mutrace = $(DEFAULT_CC)
+LDXX_mutrace = $(DEFAULT_CXX)
+CPPFLAGS_mutrace = -O0
+LDFLAGS_mutrace = -rdynamic
+DEFINES_mutrace = _DEBUG DEBUG
VALID_CONFIG_memcheck = 1
CC_memcheck = $(DEFAULT_CC)
@@ -169,45 +219,25 @@
DEFINES_memcheck = _DEBUG DEBUG
DEFINES_memcheck += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=10
-VALID_CONFIG_asan = 1
-REQUIRE_CUSTOM_LIBRARIES_asan = 1
-CC_asan = clang
-CXX_asan = clang++
-LD_asan = clang
-LDXX_asan = clang++
-CPPFLAGS_asan = -O0 -fsanitize=address -fno-omit-frame-pointer -Wno-unused-command-line-argument -DGPR_NO_DIRECT_SYSCALLS
-LDFLAGS_asan = -fsanitize=address
-DEFINES_asan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=3
+VALID_CONFIG_etsan = 1
+REQUIRE_CUSTOM_LIBRARIES_etsan = 1
+CC_etsan = clang
+CXX_etsan = clang++
+LD_etsan = clang
+LDXX_etsan = clang++
+CPPFLAGS_etsan = -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-unused-command-line-argument -fPIE -pie -DGPR_NO_DIRECT_SYSCALLS
+LDFLAGS_etsan = -fsanitize=thread -fPIE -pie $(if $(JENKINS_BUILD),-Wl$(comma)-Ttext-segment=0x7e0000000000,)
+DEFINES_etsan = _DEBUG DEBUG GRPC_EXECUTION_CONTEXT_SANITIZER
+DEFINES_etsan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=5
-VALID_CONFIG_tsan = 1
-REQUIRE_CUSTOM_LIBRARIES_tsan = 1
-CC_tsan = clang
-CXX_tsan = clang++
-LD_tsan = clang
-LDXX_tsan = clang++
-CPPFLAGS_tsan = -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-unused-command-line-argument -fPIE -pie -DGPR_NO_DIRECT_SYSCALLS
-LDFLAGS_tsan = -fsanitize=thread -fPIE -pie $(if $(JENKINS_BUILD),-Wl$(comma)-Ttext-segment=0x7e0000000000,)
-DEFINES_tsan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=5
-
-VALID_CONFIG_msan = 1
-REQUIRE_CUSTOM_LIBRARIES_msan = 1
-CC_msan = clang
-CXX_msan = clang++
-LD_msan = clang
-LDXX_msan = clang++
-CPPFLAGS_msan = -O0 -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1 -Wno-unused-command-line-argument -fPIE -pie -DGPR_NO_DIRECT_SYSCALLS
-LDFLAGS_msan = -fsanitize=memory -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1 -fPIE -pie $(if $(JENKINS_BUILD),-Wl$(comma)-Ttext-segment=0x7e0000000000,)
-DEFINES_msan = NDEBUG
-DEFINES_msan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=4
-
-VALID_CONFIG_mutrace = 1
-CC_mutrace = $(DEFAULT_CC)
-CXX_mutrace = $(DEFAULT_CXX)
-LD_mutrace = $(DEFAULT_CC)
-LDXX_mutrace = $(DEFAULT_CXX)
-CPPFLAGS_mutrace = -O0
-LDFLAGS_mutrace = -rdynamic
-DEFINES_mutrace = _DEBUG DEBUG
+VALID_CONFIG_gcov = 1
+CC_gcov = gcc
+CXX_gcov = g++
+LD_gcov = gcc
+LDXX_gcov = g++
+CPPFLAGS_gcov = -O0 -fprofile-arcs -ftest-coverage -Wno-return-type
+LDFLAGS_gcov = -fprofile-arcs -ftest-coverage -rdynamic
+DEFINES_gcov = _DEBUG DEBUG GPR_GCOV
diff --git a/build.yaml b/build.yaml
index 83b7714..1f01024 100644
--- a/build.yaml
+++ b/build.yaml
@@ -2745,6 +2745,36 @@
dbg:
CPPFLAGS: -O0
DEFINES: _DEBUG DEBUG
+ easan:
+ CC: clang
+ CPPFLAGS: -O0 -fsanitize=address -fno-omit-frame-pointer -Wno-unused-command-line-argument
+ -DGPR_NO_DIRECT_SYSCALLS
+ CXX: clang++
+ DEFINES: _DEBUG DEBUG GRPC_EXECUTION_CONTEXT_SANITIZER
+ LD: clang
+ LDFLAGS: -fsanitize=address
+ LDXX: clang++
+ compile_the_world: true
+ test_environ:
+ ASAN_OPTIONS: detect_leaks=1:color=always
+ LSAN_OPTIONS: suppressions=tools/lsan_suppressions.txt:report_objects=1
+ timeout_multiplier: 3
+ edbg:
+ CPPFLAGS: -O0
+ DEFINES: _DEBUG DEBUG GRPC_EXECUTION_CONTEXT_SANITIZER
+ etsan:
+ CC: clang
+ CPPFLAGS: -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-unused-command-line-argument
+ -fPIE -pie -DGPR_NO_DIRECT_SYSCALLS
+ CXX: clang++
+ DEFINES: _DEBUG DEBUG GRPC_EXECUTION_CONTEXT_SANITIZER
+ LD: clang
+ LDFLAGS: -fsanitize=thread -fPIE -pie $(if $(JENKINS_BUILD),-Wl$(comma)-Ttext-segment=0x7e0000000000,)
+ LDXX: clang++
+ compile_the_world: true
+ test_environ:
+ TSAN_OPTIONS: suppressions=tools/tsan_suppressions.txt:halt_on_error=1:second_deadlock_stack=1
+ timeout_multiplier: 5
gcov:
CC: gcc
CPPFLAGS: -O0 -fprofile-arcs -ftest-coverage -Wno-return-type
diff --git a/src/core/iomgr/exec_ctx.c b/src/core/iomgr/exec_ctx.c
index 1fd79f6..893fe45 100644
--- a/src/core/iomgr/exec_ctx.c
+++ b/src/core/iomgr/exec_ctx.c
@@ -34,9 +34,12 @@
#include "src/core/iomgr/exec_ctx.h"
#include <grpc/support/log.h>
+#include <grpc/support/sync.h>
+#include <grpc/support/thd.h>
#include "src/core/profiling/timers.h"
+#ifndef GRPC_EXECUTION_CONTEXT_SANITIZER
bool grpc_exec_ctx_flush(grpc_exec_ctx *exec_ctx) {
bool did_something = 0;
GPR_TIMER_BEGIN("grpc_exec_ctx_flush", 0);
@@ -74,3 +77,75 @@
GPR_ASSERT(offload_target_or_null == NULL);
grpc_closure_list_move(list, &exec_ctx->closure_list);
}
+
+void grpc_exec_ctx_global_init(void) {}
+void grpc_exec_ctx_global_shutdown(void) {}
+#else
+static gpr_mu g_mu;
+static gpr_cv g_cv;
+static int g_threads = 0;
+
+static void run_closure(void *arg) {
+ grpc_closure *closure = arg;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ closure->cb(&exec_ctx, closure->cb_arg, (closure->final_data & 1) != 0);
+ grpc_exec_ctx_finish(&exec_ctx);
+ gpr_mu_lock(&g_mu);
+ if (--g_threads == 0) {
+ gpr_cv_signal(&g_cv);
+ }
+ gpr_mu_unlock(&g_mu);
+}
+
+static void start_closure(grpc_closure *closure) {
+ gpr_thd_id id;
+ gpr_mu_lock(&g_mu);
+ g_threads++;
+ gpr_mu_unlock(&g_mu);
+ gpr_thd_new(&id, run_closure, closure, NULL);
+}
+
+bool grpc_exec_ctx_flush(grpc_exec_ctx *exec_ctx) { return false; }
+
+void grpc_exec_ctx_finish(grpc_exec_ctx *exec_ctx) {}
+
+void grpc_exec_ctx_enqueue(grpc_exec_ctx *exec_ctx, grpc_closure *closure,
+ bool success,
+ grpc_workqueue *offload_target_or_null) {
+ GPR_ASSERT(offload_target_or_null == NULL);
+ if (closure == NULL) return;
+ closure->final_data = success;
+ start_closure(closure);
+}
+
+void grpc_exec_ctx_enqueue_list(grpc_exec_ctx *exec_ctx,
+ grpc_closure_list *list,
+ grpc_workqueue *offload_target_or_null) {
+ GPR_ASSERT(offload_target_or_null == NULL);
+ if (list == NULL) return;
+ grpc_closure *p = list->head;
+ while (p) {
+ grpc_closure *start = p;
+ p = grpc_closure_next(start);
+ start_closure(start);
+ }
+ grpc_closure_list r = GRPC_CLOSURE_LIST_INIT;
+ *list = r;
+}
+
+void grpc_exec_ctx_global_init(void) {
+ gpr_mu_init(&g_mu);
+ gpr_cv_init(&g_cv);
+}
+
+void grpc_exec_ctx_global_shutdown(void) {
+ gpr_mu_lock(&g_mu);
+ while (g_threads != 0) {
+ gpr_cv_wait(&g_cv, &g_mu, gpr_inf_future(GPR_CLOCK_REALTIME));
+ }
+ gpr_mu_unlock(&g_mu);
+
+ gpr_mu_destroy(&g_mu);
+ gpr_cv_destroy(&g_cv);
+}
+#endif
diff --git a/src/core/iomgr/exec_ctx.h b/src/core/iomgr/exec_ctx.h
index 9a9b2e5..1b627a5 100644
--- a/src/core/iomgr/exec_ctx.h
+++ b/src/core/iomgr/exec_ctx.h
@@ -36,6 +36,14 @@
#include "src/core/iomgr/closure.h"
+/* #define GRPC_EXECUTION_CONTEXT_SANITIZER 1 */
+
+/** A workqueue represents a list of work to be executed asynchronously.
+ Forward declared here to avoid a circular dependency with workqueue.h. */
+struct grpc_workqueue;
+typedef struct grpc_workqueue grpc_workqueue;
+
+#ifndef GRPC_EXECUTION_CONTEXT_SANITIZER
/** Execution context.
* A bag of data that collects information along a callstack.
* Generally created at public API entry points, and passed down as
@@ -57,13 +65,15 @@
grpc_closure_list closure_list;
};
-/** A workqueue represents a list of work to be executed asynchronously.
- Forward declared here to avoid a circular dependency with workqueue.h. */
-struct grpc_workqueue;
-typedef struct grpc_workqueue grpc_workqueue;
-
#define GRPC_EXEC_CTX_INIT \
{ GRPC_CLOSURE_LIST_INIT }
+#else
+struct grpc_exec_ctx {
+ int unused;
+};
+#define GRPC_EXEC_CTX_INIT \
+ { 0 }
+#endif
/** Flush any work that has been enqueued onto this grpc_exec_ctx.
* Caller must guarantee that no interfering locks are held.
@@ -82,4 +92,7 @@
grpc_closure_list *list,
grpc_workqueue *offload_target_or_null);
+void grpc_exec_ctx_global_init(void);
+void grpc_exec_ctx_global_shutdown(void);
+
#endif
diff --git a/src/core/iomgr/iomgr.c b/src/core/iomgr/iomgr.c
index 9c89c2c..3ab4430 100644
--- a/src/core/iomgr/iomgr.c
+++ b/src/core/iomgr/iomgr.c
@@ -43,6 +43,7 @@
#include <grpc/support/thd.h>
#include <grpc/support/useful.h>
+#include "src/core/iomgr/exec_ctx.h"
#include "src/core/iomgr/iomgr_internal.h"
#include "src/core/iomgr/timer.h"
#include "src/core/support/env.h"
@@ -57,6 +58,7 @@
g_shutdown = 0;
gpr_mu_init(&g_mu);
gpr_cv_init(&g_rcv);
+ grpc_exec_ctx_global_init();
grpc_timer_list_init(gpr_now(GPR_CLOCK_MONOTONIC));
g_root_object.next = g_root_object.prev = &g_root_object;
g_root_object.name = "root";
@@ -138,6 +140,7 @@
grpc_pollset_global_shutdown();
grpc_iomgr_platform_shutdown();
+ grpc_exec_ctx_global_shutdown();
gpr_mu_destroy(&g_mu);
gpr_cv_destroy(&g_rcv);
}
diff --git a/src/core/iomgr/workqueue_posix.c b/src/core/iomgr/workqueue_posix.c
index c096dbf..2b42e6d 100644
--- a/src/core/iomgr/workqueue_posix.c
+++ b/src/core/iomgr/workqueue_posix.c
@@ -107,7 +107,7 @@
if (grpc_closure_list_empty(workqueue->closure_list)) {
grpc_wakeup_fd_wakeup(&workqueue->wakeup_fd);
}
- grpc_closure_list_move(&exec_ctx->closure_list, &workqueue->closure_list);
+ grpc_exec_ctx_enqueue_list(exec_ctx, &workqueue->closure_list, NULL);
gpr_mu_unlock(&workqueue->mu);
}
@@ -123,7 +123,7 @@
gpr_free(workqueue);
} else {
gpr_mu_lock(&workqueue->mu);
- grpc_closure_list_move(&workqueue->closure_list, &exec_ctx->closure_list);
+ grpc_exec_ctx_enqueue_list(exec_ctx, &workqueue->closure_list, NULL);
grpc_wakeup_fd_consume_wakeup(&workqueue->wakeup_fd);
gpr_mu_unlock(&workqueue->mu);
grpc_fd_notify_on_read(exec_ctx, workqueue->wakeup_read_fd,
diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/call.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/call.pyx.pxi
index 80f4da5..d1b9c98 100644
--- a/src/python/grpcio/grpc/_cython/_cygrpc/call.pyx.pxi
+++ b/src/python/grpcio/grpc/_cython/_cygrpc/call.pyx.pxi
@@ -1,4 +1,4 @@
-# Copyright 2015, Google Inc.
+# Copyright 2015-2016, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -40,14 +40,17 @@
def start_batch(self, operations, tag):
if not self.is_valid:
raise ValueError("invalid call object cannot be used from Python")
+ cdef grpc_call_error result
cdef Operations cy_operations = Operations(operations)
cdef OperationTag operation_tag = OperationTag(tag)
operation_tag.operation_call = self
operation_tag.batch_operations = cy_operations
cpython.Py_INCREF(operation_tag)
- return grpc_call_start_batch(
- self.c_call, cy_operations.c_ops, cy_operations.c_nops,
- <cpython.PyObject *>operation_tag, NULL)
+ with nogil:
+ result = grpc_call_start_batch(
+ self.c_call, cy_operations.c_ops, cy_operations.c_nops,
+ <cpython.PyObject *>operation_tag, NULL)
+ return result
def cancel(
self, grpc_status_code error_code=GRPC_STATUS__DO_NOT_USE,
@@ -57,6 +60,8 @@
if (details is None) != (error_code == GRPC_STATUS__DO_NOT_USE):
raise ValueError("if error_code is specified, so must details "
"(and vice-versa)")
+ cdef grpc_call_error result
+ cdef char *c_details = NULL
if error_code != GRPC_STATUS__DO_NOT_USE:
if isinstance(details, bytes):
pass
@@ -65,25 +70,37 @@
else:
raise TypeError("expected details to be str or bytes")
self.references.append(details)
- return grpc_call_cancel_with_status(
- self.c_call, error_code, details, NULL)
+ c_details = details
+ with nogil:
+ result = grpc_call_cancel_with_status(
+ self.c_call, error_code, c_details, NULL)
+ return result
else:
- return grpc_call_cancel(self.c_call, NULL)
+ with nogil:
+ result = grpc_call_cancel(self.c_call, NULL)
+ return result
def set_credentials(
self, CallCredentials call_credentials not None):
- return grpc_call_set_credentials(
- self.c_call, call_credentials.c_credentials)
+ cdef grpc_call_error result
+ with nogil:
+ result = grpc_call_set_credentials(
+ self.c_call, call_credentials.c_credentials)
+ return result
def peer(self):
- cdef char *peer = grpc_call_get_peer(self.c_call)
+ cdef char *peer = NULL
+ with nogil:
+ peer = grpc_call_get_peer(self.c_call)
result = <bytes>peer
- gpr_free(peer)
+ with nogil:
+ gpr_free(peer)
return result
def __dealloc__(self):
if self.c_call != NULL:
- grpc_call_destroy(self.c_call)
+ with nogil:
+ grpc_call_destroy(self.c_call)
# The object *should* always be valid from Python. Used for debugging.
@property
diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi
index bc03c4d..d612c90 100644
--- a/src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi
+++ b/src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi
@@ -35,6 +35,7 @@
def __cinit__(self, target, ChannelArgs arguments=None,
ChannelCredentials channel_credentials=None):
cdef grpc_channel_args *c_arguments = NULL
+ cdef char *c_target = NULL
self.c_channel = NULL
self.references = []
if arguments is not None:
@@ -45,12 +46,15 @@
target = target.encode()
else:
raise TypeError("expected target to be str or bytes")
+ c_target = target
if channel_credentials is None:
- self.c_channel = grpc_insecure_channel_create(target, c_arguments,
- NULL)
+ with nogil:
+ self.c_channel = grpc_insecure_channel_create(c_target, c_arguments,
+ NULL)
else:
- self.c_channel = grpc_secure_channel_create(
- channel_credentials.c_credentials, target, c_arguments, NULL)
+ with nogil:
+ self.c_channel = grpc_secure_channel_create(
+ channel_credentials.c_credentials, c_target, c_arguments, NULL)
self.references.append(channel_credentials)
self.references.append(target)
self.references.append(arguments)
@@ -66,6 +70,7 @@
method = method.encode()
else:
raise TypeError("expected method to be str or bytes")
+ cdef char *method_c_string = method
cdef char *host_c_string = NULL
if host is None:
pass
@@ -81,31 +86,40 @@
cdef grpc_call *parent_call = NULL
if parent is not None:
parent_call = parent.c_call
- operation_call.c_call = grpc_channel_create_call(
- self.c_channel, parent_call, flags,
- queue.c_completion_queue, method, host_c_string, deadline.c_time,
- NULL)
+ with nogil:
+ operation_call.c_call = grpc_channel_create_call(
+ self.c_channel, parent_call, flags,
+ queue.c_completion_queue, method_c_string, host_c_string,
+ deadline.c_time, NULL)
return operation_call
def check_connectivity_state(self, bint try_to_connect):
- return grpc_channel_check_connectivity_state(self.c_channel,
- try_to_connect)
+ cdef grpc_connectivity_state result
+ with nogil:
+ result = grpc_channel_check_connectivity_state(self.c_channel,
+ try_to_connect)
+ return result
def watch_connectivity_state(
self, grpc_connectivity_state last_observed_state,
Timespec deadline not None, CompletionQueue queue not None, tag):
cdef OperationTag operation_tag = OperationTag(tag)
cpython.Py_INCREF(operation_tag)
- grpc_channel_watch_connectivity_state(
- self.c_channel, last_observed_state, deadline.c_time,
- queue.c_completion_queue, <cpython.PyObject *>operation_tag)
+ with nogil:
+ grpc_channel_watch_connectivity_state(
+ self.c_channel, last_observed_state, deadline.c_time,
+ queue.c_completion_queue, <cpython.PyObject *>operation_tag)
def target(self):
- cdef char * target = grpc_channel_get_target(self.c_channel)
+ cdef char *target = NULL
+ with nogil:
+ target = grpc_channel_get_target(self.c_channel)
result = <bytes>target
- gpr_free(target)
+ with nogil:
+ gpr_free(target)
return result
def __dealloc__(self):
if self.c_channel != NULL:
- grpc_channel_destroy(self.c_channel)
+ with nogil:
+ grpc_channel_destroy(self.c_channel)
diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/completion_queue.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/completion_queue.pyx.pxi
index e11138b..09e47d4 100644
--- a/src/python/grpcio/grpc/_cython/_cygrpc/completion_queue.pyx.pxi
+++ b/src/python/grpcio/grpc/_cython/_cygrpc/completion_queue.pyx.pxi
@@ -36,7 +36,8 @@
cdef class CompletionQueue:
def __cinit__(self):
- self.c_completion_queue = grpc_completion_queue_create(NULL)
+ with nogil:
+ self.c_completion_queue = grpc_completion_queue_create(NULL)
self.is_shutting_down = False
self.is_shutdown = False
self.pluck_condition = threading.Condition()
@@ -82,8 +83,9 @@
def poll(self, Timespec deadline=None):
# We name this 'poll' to avoid problems with CPython's expectations for
# 'special' methods (like next and __next__).
- cdef gpr_timespec c_deadline = gpr_inf_future(
- GPR_CLOCK_REALTIME)
+ cdef gpr_timespec c_deadline
+ with nogil:
+ c_deadline = gpr_inf_future(GPR_CLOCK_REALTIME)
if deadline is not None:
c_deadline = deadline.c_time
cdef grpc_event event
@@ -123,7 +125,8 @@
return self._interpret_event(event)
def shutdown(self):
- grpc_completion_queue_shutdown(self.c_completion_queue)
+ with nogil:
+ grpc_completion_queue_shutdown(self.c_completion_queue)
self.is_shutting_down = True
def clear(self):
@@ -133,15 +136,19 @@
pass
def __dealloc__(self):
- cdef gpr_timespec c_deadline = gpr_inf_future(GPR_CLOCK_REALTIME)
+ cdef gpr_timespec c_deadline
+ with nogil:
+ c_deadline = gpr_inf_future(GPR_CLOCK_REALTIME)
if self.c_completion_queue != NULL:
# Ensure shutdown
if not self.is_shutting_down:
- grpc_completion_queue_shutdown(self.c_completion_queue)
+ with nogil:
+ grpc_completion_queue_shutdown(self.c_completion_queue)
# Pump the queue
while not self.is_shutdown:
with nogil:
event = grpc_completion_queue_next(
self.c_completion_queue, c_deadline, NULL)
self._interpret_event(event)
- grpc_completion_queue_destroy(self.c_completion_queue)
+ with nogil:
+ grpc_completion_queue_destroy(self.c_completion_queue)
diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi
index 3f439c8..1d7adca 100644
--- a/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi
+++ b/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi
@@ -1,4 +1,4 @@
-# Copyright 2015, Google Inc.
+# Copyright 2015-2016, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -46,7 +46,8 @@
def __dealloc__(self):
if self.c_credentials != NULL:
- grpc_channel_credentials_release(self.c_credentials)
+ with nogil:
+ grpc_channel_credentials_release(self.c_credentials)
cdef class CallCredentials:
@@ -63,7 +64,8 @@
def __dealloc__(self):
if self.c_credentials != NULL:
- grpc_call_credentials_release(self.c_credentials)
+ with nogil:
+ grpc_call_credentials_release(self.c_credentials)
cdef class ServerCredentials:
@@ -74,7 +76,8 @@
def __dealloc__(self):
if self.c_credentials != NULL:
- grpc_server_credentials_release(self.c_credentials)
+ with nogil:
+ grpc_server_credentials_release(self.c_credentials)
cdef class CredentialsMetadataPlugin:
@@ -139,7 +142,8 @@
def channel_credentials_google_default():
cdef ChannelCredentials credentials = ChannelCredentials();
- credentials.c_credentials = grpc_google_default_credentials_create()
+ with nogil:
+ credentials.c_credentials = grpc_google_default_credentials_create()
return credentials
def channel_credentials_ssl(pem_root_certificates,
@@ -158,12 +162,14 @@
c_pem_root_certificates = pem_root_certificates
credentials.references.append(pem_root_certificates)
if ssl_pem_key_cert_pair is not None:
- credentials.c_credentials = grpc_ssl_credentials_create(
- c_pem_root_certificates, &ssl_pem_key_cert_pair.c_pair, NULL)
+ with nogil:
+ credentials.c_credentials = grpc_ssl_credentials_create(
+ c_pem_root_certificates, &ssl_pem_key_cert_pair.c_pair, NULL)
credentials.references.append(ssl_pem_key_cert_pair)
else:
- credentials.c_credentials = grpc_ssl_credentials_create(
- c_pem_root_certificates, NULL, NULL)
+ with nogil:
+ credentials.c_credentials = grpc_ssl_credentials_create(
+ c_pem_root_certificates, NULL, NULL)
return credentials
def channel_credentials_composite(
@@ -172,8 +178,9 @@
if not credentials_1.is_valid or not credentials_2.is_valid:
raise ValueError("passed credentials must both be valid")
cdef ChannelCredentials credentials = ChannelCredentials()
- credentials.c_credentials = grpc_composite_channel_credentials_create(
- credentials_1.c_credentials, credentials_2.c_credentials, NULL)
+ with nogil:
+ credentials.c_credentials = grpc_composite_channel_credentials_create(
+ credentials_1.c_credentials, credentials_2.c_credentials, NULL)
credentials.references.append(credentials_1)
credentials.references.append(credentials_2)
return credentials
@@ -184,16 +191,18 @@
if not credentials_1.is_valid or not credentials_2.is_valid:
raise ValueError("passed credentials must both be valid")
cdef CallCredentials credentials = CallCredentials()
- credentials.c_credentials = grpc_composite_call_credentials_create(
- credentials_1.c_credentials, credentials_2.c_credentials, NULL)
+ with nogil:
+ credentials.c_credentials = grpc_composite_call_credentials_create(
+ credentials_1.c_credentials, credentials_2.c_credentials, NULL)
credentials.references.append(credentials_1)
credentials.references.append(credentials_2)
return credentials
def call_credentials_google_compute_engine():
cdef CallCredentials credentials = CallCredentials()
- credentials.c_credentials = (
- grpc_google_compute_engine_credentials_create(NULL))
+ with nogil:
+ credentials.c_credentials = (
+ grpc_google_compute_engine_credentials_create(NULL))
return credentials
def call_credentials_service_account_jwt_access(
@@ -205,9 +214,11 @@
else:
raise TypeError("expected json_key to be str or bytes")
cdef CallCredentials credentials = CallCredentials()
- credentials.c_credentials = (
- grpc_service_account_jwt_access_credentials_create(
- json_key, token_lifetime.c_time, NULL))
+ cdef char *json_key_c_string = json_key
+ with nogil:
+ credentials.c_credentials = (
+ grpc_service_account_jwt_access_credentials_create(
+ json_key_c_string, token_lifetime.c_time, NULL))
credentials.references.append(json_key)
return credentials
@@ -219,8 +230,10 @@
else:
raise TypeError("expected json_refresh_token to be str or bytes")
cdef CallCredentials credentials = CallCredentials()
- credentials.c_credentials = grpc_google_refresh_token_credentials_create(
- json_refresh_token, NULL)
+ cdef char *json_refresh_token_c_string = json_refresh_token
+ with nogil:
+ credentials.c_credentials = grpc_google_refresh_token_credentials_create(
+ json_refresh_token_c_string, NULL)
credentials.references.append(json_refresh_token)
return credentials
@@ -238,17 +251,21 @@
else:
raise TypeError("expected authority_selector to be str or bytes")
cdef CallCredentials credentials = CallCredentials()
- credentials.c_credentials = grpc_google_iam_credentials_create(
- authorization_token, authority_selector, NULL)
+ cdef char *authorization_token_c_string = authorization_token
+ cdef char *authority_selector_c_string = authority_selector
+ with nogil:
+ credentials.c_credentials = grpc_google_iam_credentials_create(
+ authorization_token_c_string, authority_selector_c_string, NULL)
credentials.references.append(authorization_token)
credentials.references.append(authority_selector)
return credentials
def call_credentials_metadata_plugin(CredentialsMetadataPlugin plugin):
cdef CallCredentials credentials = CallCredentials()
- credentials.c_credentials = (
- grpc_metadata_credentials_create_from_plugin(plugin.make_c_plugin(),
- NULL))
+ cdef grpc_metadata_credentials_plugin c_plugin = plugin.make_c_plugin()
+ with nogil:
+ credentials.c_credentials = (
+ grpc_metadata_credentials_create_from_plugin(c_plugin, NULL))
# TODO(atash): the following held reference is *probably* never necessary
credentials.references.append(plugin)
return credentials
@@ -274,11 +291,12 @@
credentials.references.append(pem_key_cert_pairs)
credentials.references.append(pem_root_certs)
credentials.c_ssl_pem_key_cert_pairs_count = len(pem_key_cert_pairs)
- credentials.c_ssl_pem_key_cert_pairs = (
- <grpc_ssl_pem_key_cert_pair *>gpr_malloc(
- sizeof(grpc_ssl_pem_key_cert_pair) *
- credentials.c_ssl_pem_key_cert_pairs_count
- ))
+ with nogil:
+ credentials.c_ssl_pem_key_cert_pairs = (
+ <grpc_ssl_pem_key_cert_pair *>gpr_malloc(
+ sizeof(grpc_ssl_pem_key_cert_pair) *
+ credentials.c_ssl_pem_key_cert_pairs_count
+ ))
for i in range(credentials.c_ssl_pem_key_cert_pairs_count):
credentials.c_ssl_pem_key_cert_pairs[i] = (
(<SslPemKeyCertPair>pem_key_cert_pairs[i]).c_pair)
diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi
index dbf0045..61165cb 100644
--- a/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi
+++ b/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi
@@ -38,27 +38,27 @@
int pygrpc_load_core(char*)
- void *gpr_malloc(size_t size)
- void gpr_free(void *ptr)
- void *gpr_realloc(void *p, size_t size)
+ void *gpr_malloc(size_t size) nogil
+ void gpr_free(void *ptr) nogil
+ void *gpr_realloc(void *p, size_t size) nogil
ctypedef struct gpr_slice:
# don't worry about writing out the members of gpr_slice; we never access
# them directly.
pass
- gpr_slice gpr_slice_ref(gpr_slice s)
- void gpr_slice_unref(gpr_slice s)
- gpr_slice gpr_slice_new(void *p, size_t len, void (*destroy)(void *))
+ gpr_slice gpr_slice_ref(gpr_slice s) nogil
+ void gpr_slice_unref(gpr_slice s) nogil
+ gpr_slice gpr_slice_new(void *p, size_t len, void (*destroy)(void *)) nogil
gpr_slice gpr_slice_new_with_len(
- void *p, size_t len, void (*destroy)(void *, size_t))
- gpr_slice gpr_slice_malloc(size_t length)
- gpr_slice gpr_slice_from_copied_string(const char *source)
- gpr_slice gpr_slice_from_copied_buffer(const char *source, size_t len)
+ void *p, size_t len, void (*destroy)(void *, size_t)) nogil
+ gpr_slice gpr_slice_malloc(size_t length) nogil
+ gpr_slice gpr_slice_from_copied_string(const char *source) nogil
+ gpr_slice gpr_slice_from_copied_buffer(const char *source, size_t len) nogil
# Declare functions for function-like macros (because Cython)...
- void *gpr_slice_start_ptr "GPR_SLICE_START_PTR" (gpr_slice s)
- size_t gpr_slice_length "GPR_SLICE_LENGTH" (gpr_slice s)
+ void *gpr_slice_start_ptr "GPR_SLICE_START_PTR" (gpr_slice s) nogil
+ size_t gpr_slice_length "GPR_SLICE_LENGTH" (gpr_slice s) nogil
ctypedef enum gpr_clock_type:
GPR_CLOCK_MONOTONIC
@@ -71,14 +71,14 @@
int32_t nanoseconds "tv_nsec"
gpr_clock_type clock_type
- gpr_timespec gpr_time_0(gpr_clock_type type)
- gpr_timespec gpr_inf_future(gpr_clock_type type)
- gpr_timespec gpr_inf_past(gpr_clock_type type)
+ gpr_timespec gpr_time_0(gpr_clock_type type) nogil
+ gpr_timespec gpr_inf_future(gpr_clock_type type) nogil
+ gpr_timespec gpr_inf_past(gpr_clock_type type) nogil
- gpr_timespec gpr_now(gpr_clock_type clock)
+ gpr_timespec gpr_now(gpr_clock_type clock) nogil
gpr_timespec gpr_convert_clock_type(gpr_timespec t,
- gpr_clock_type target_clock)
+ gpr_clock_type target_clock) nogil
ctypedef enum grpc_status_code:
GRPC_STATUS_OK
@@ -114,15 +114,15 @@
pass
grpc_byte_buffer *grpc_raw_byte_buffer_create(gpr_slice *slices,
- size_t nslices)
- size_t grpc_byte_buffer_length(grpc_byte_buffer *bb)
- void grpc_byte_buffer_destroy(grpc_byte_buffer *byte_buffer)
+ size_t nslices) nogil
+ size_t grpc_byte_buffer_length(grpc_byte_buffer *bb) nogil
+ void grpc_byte_buffer_destroy(grpc_byte_buffer *byte_buffer) nogil
void grpc_byte_buffer_reader_init(grpc_byte_buffer_reader *reader,
- grpc_byte_buffer *buffer)
+ grpc_byte_buffer *buffer) nogil
int grpc_byte_buffer_reader_next(grpc_byte_buffer_reader *reader,
- gpr_slice *slice)
- void grpc_byte_buffer_reader_destroy(grpc_byte_buffer_reader *reader)
+ gpr_slice *slice) nogil
+ void grpc_byte_buffer_reader_destroy(grpc_byte_buffer_reader *reader) nogil
const char *GRPC_ARG_PRIMARY_USER_AGENT_STRING
const char *GRPC_ARG_ENABLE_CENSUS
@@ -221,8 +221,8 @@
size_t capacity
grpc_metadata *metadata
- void grpc_metadata_array_init(grpc_metadata_array *array)
- void grpc_metadata_array_destroy(grpc_metadata_array *array)
+ void grpc_metadata_array_init(grpc_metadata_array *array) nogil
+ void grpc_metadata_array_destroy(grpc_metadata_array *array) nogil
ctypedef struct grpc_call_details:
char *method
@@ -231,8 +231,8 @@
size_t host_capacity
gpr_timespec deadline
- void grpc_call_details_init(grpc_call_details *details)
- void grpc_call_details_destroy(grpc_call_details *details)
+ void grpc_call_details_init(grpc_call_details *details) nogil
+ void grpc_call_details_destroy(grpc_call_details *details) nogil
ctypedef enum grpc_op_type:
GRPC_OP_SEND_INITIAL_METADATA
@@ -277,61 +277,62 @@
uint32_t flags
grpc_op_data data
- void grpc_init()
- void grpc_shutdown()
+ void grpc_init() nogil
+ void grpc_shutdown() nogil
- grpc_completion_queue *grpc_completion_queue_create(void *reserved)
+ grpc_completion_queue *grpc_completion_queue_create(void *reserved) nogil
grpc_event grpc_completion_queue_next(grpc_completion_queue *cq,
gpr_timespec deadline,
void *reserved) nogil
grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cq, void *tag,
gpr_timespec deadline,
void *reserved) nogil
- void grpc_completion_queue_shutdown(grpc_completion_queue *cq)
- void grpc_completion_queue_destroy(grpc_completion_queue *cq)
+ void grpc_completion_queue_shutdown(grpc_completion_queue *cq) nogil
+ void grpc_completion_queue_destroy(grpc_completion_queue *cq) nogil
- grpc_call_error grpc_call_start_batch(grpc_call *call, const grpc_op *ops,
- size_t nops, void *tag, void *reserved)
- grpc_call_error grpc_call_cancel(grpc_call *call, void *reserved)
+ grpc_call_error grpc_call_start_batch(
+ grpc_call *call, const grpc_op *ops, size_t nops, void *tag,
+ void *reserved) nogil
+ grpc_call_error grpc_call_cancel(grpc_call *call, void *reserved) nogil
grpc_call_error grpc_call_cancel_with_status(grpc_call *call,
grpc_status_code status,
const char *description,
- void *reserved)
- char *grpc_call_get_peer(grpc_call *call)
- void grpc_call_destroy(grpc_call *call)
+ void *reserved) nogil
+ char *grpc_call_get_peer(grpc_call *call) nogil
+ void grpc_call_destroy(grpc_call *call) nogil
grpc_channel *grpc_insecure_channel_create(const char *target,
const grpc_channel_args *args,
- void *reserved)
- grpc_call *grpc_channel_create_call(grpc_channel *channel,
- grpc_call *parent_call,
- uint32_t propagation_mask,
- grpc_completion_queue *completion_queue,
- const char *method, const char *host,
- gpr_timespec deadline, void *reserved)
+ void *reserved) nogil
+ grpc_call *grpc_channel_create_call(
+ grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask,
+ grpc_completion_queue *completion_queue, const char *method,
+ const char *host, gpr_timespec deadline, void *reserved) nogil
grpc_connectivity_state grpc_channel_check_connectivity_state(
- grpc_channel *channel, int try_to_connect)
+ grpc_channel *channel, int try_to_connect) nogil
void grpc_channel_watch_connectivity_state(
grpc_channel *channel, grpc_connectivity_state last_observed_state,
- gpr_timespec deadline, grpc_completion_queue *cq, void *tag)
- char *grpc_channel_get_target(grpc_channel *channel)
- void grpc_channel_destroy(grpc_channel *channel)
+ gpr_timespec deadline, grpc_completion_queue *cq, void *tag) nogil
+ char *grpc_channel_get_target(grpc_channel *channel) nogil
+ void grpc_channel_destroy(grpc_channel *channel) nogil
- grpc_server *grpc_server_create(const grpc_channel_args *args, void *reserved)
+ grpc_server *grpc_server_create(
+ const grpc_channel_args *args, void *reserved) nogil
grpc_call_error grpc_server_request_call(
grpc_server *server, grpc_call **call, grpc_call_details *details,
grpc_metadata_array *request_metadata, grpc_completion_queue
*cq_bound_to_call, grpc_completion_queue *cq_for_notification, void
- *tag_new)
+ *tag_new) nogil
void grpc_server_register_completion_queue(grpc_server *server,
grpc_completion_queue *cq,
- void *reserved)
- int grpc_server_add_insecure_http2_port(grpc_server *server, const char *addr)
- void grpc_server_start(grpc_server *server)
+ void *reserved) nogil
+ int grpc_server_add_insecure_http2_port(
+ grpc_server *server, const char *addr) nogil
+ void grpc_server_start(grpc_server *server) nogil
void grpc_server_shutdown_and_notify(
- grpc_server *server, grpc_completion_queue *cq, void *tag)
- void grpc_server_cancel_all_calls(grpc_server *server)
- void grpc_server_destroy(grpc_server *server)
+ grpc_server *server, grpc_completion_queue *cq, void *tag) nogil
+ void grpc_server_cancel_all_calls(grpc_server *server) nogil
+ void grpc_server_destroy(grpc_server *server) nogil
ctypedef struct grpc_ssl_pem_key_cert_pair:
const char *private_key
@@ -347,35 +348,36 @@
ctypedef void (*grpc_ssl_roots_override_callback)(char **pem_root_certs)
- void grpc_set_ssl_roots_override_callback(grpc_ssl_roots_override_callback cb)
+ void grpc_set_ssl_roots_override_callback(
+ grpc_ssl_roots_override_callback cb) nogil
- grpc_channel_credentials *grpc_google_default_credentials_create()
+ grpc_channel_credentials *grpc_google_default_credentials_create() nogil
grpc_channel_credentials *grpc_ssl_credentials_create(
const char *pem_root_certs, grpc_ssl_pem_key_cert_pair *pem_key_cert_pair,
- void *reserved)
+ void *reserved) nogil
grpc_channel_credentials *grpc_composite_channel_credentials_create(
grpc_channel_credentials *creds1, grpc_call_credentials *creds2,
- void *reserved)
- void grpc_channel_credentials_release(grpc_channel_credentials *creds)
+ void *reserved) nogil
+ void grpc_channel_credentials_release(grpc_channel_credentials *creds) nogil
grpc_call_credentials *grpc_composite_call_credentials_create(
grpc_call_credentials *creds1, grpc_call_credentials *creds2,
- void *reserved)
+ void *reserved) nogil
grpc_call_credentials *grpc_google_compute_engine_credentials_create(
- void *reserved)
+ void *reserved) nogil
grpc_call_credentials *grpc_service_account_jwt_access_credentials_create(
const char *json_key,
- gpr_timespec token_lifetime, void *reserved)
+ gpr_timespec token_lifetime, void *reserved) nogil
grpc_call_credentials *grpc_google_refresh_token_credentials_create(
- const char *json_refresh_token, void *reserved)
+ const char *json_refresh_token, void *reserved) nogil
grpc_call_credentials *grpc_google_iam_credentials_create(
const char *authorization_token, const char *authority_selector,
- void *reserved)
- void grpc_call_credentials_release(grpc_call_credentials *creds)
+ void *reserved) nogil
+ void grpc_call_credentials_release(grpc_call_credentials *creds) nogil
grpc_channel *grpc_secure_channel_create(
grpc_channel_credentials *creds, const char *target,
- const grpc_channel_args *args, void *reserved)
+ const grpc_channel_args *args, void *reserved) nogil
ctypedef struct grpc_server_credentials:
# We don't care about the internals (and in fact don't know them)
@@ -385,13 +387,13 @@
const char *pem_root_certs,
grpc_ssl_pem_key_cert_pair *pem_key_cert_pairs,
size_t num_key_cert_pairs, int force_client_auth, void *reserved)
- void grpc_server_credentials_release(grpc_server_credentials *creds)
+ void grpc_server_credentials_release(grpc_server_credentials *creds) nogil
int grpc_server_add_secure_http2_port(grpc_server *server, const char *addr,
- grpc_server_credentials *creds)
+ grpc_server_credentials *creds) nogil
grpc_call_error grpc_call_set_credentials(grpc_call *call,
- grpc_call_credentials *creds)
+ grpc_call_credentials *creds) nogil
ctypedef struct grpc_auth_context:
# We don't care about the internals (and in fact don't know them)
@@ -415,4 +417,4 @@
const char *type
grpc_call_credentials *grpc_metadata_credentials_create_from_plugin(
- grpc_metadata_credentials_plugin plugin, void *reserved)
+ grpc_metadata_credentials_plugin plugin, void *reserved) nogil
diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi
index fa4ea99..851389a 100644
--- a/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi
+++ b/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi
@@ -107,15 +107,18 @@
def __cinit__(self, time):
if time is None:
- self.c_time = gpr_now(GPR_CLOCK_REALTIME)
+ with nogil:
+ self.c_time = gpr_now(GPR_CLOCK_REALTIME)
return
if isinstance(time, int):
time = float(time)
if isinstance(time, float):
if time == float("+inf"):
- self.c_time = gpr_inf_future(GPR_CLOCK_REALTIME)
+ with nogil:
+ self.c_time = gpr_inf_future(GPR_CLOCK_REALTIME)
elif time == float("-inf"):
- self.c_time = gpr_inf_past(GPR_CLOCK_REALTIME)
+ with nogil:
+ self.c_time = gpr_inf_past(GPR_CLOCK_REALTIME)
else:
self.c_time.seconds = time
self.c_time.nanoseconds = (time - float(self.c_time.seconds)) * 1e9
@@ -131,8 +134,10 @@
# TODO(atash) ensure that everywhere a Timespec is created that it's
# converted to GPR_CLOCK_REALTIME then and not every time someone wants to
# read values off in Python.
- cdef gpr_timespec real_time = (
- gpr_convert_clock_type(self.c_time, GPR_CLOCK_REALTIME))
+ cdef gpr_timespec real_time
+ with nogil:
+ real_time = (
+ gpr_convert_clock_type(self.c_time, GPR_CLOCK_REALTIME))
return real_time.seconds
@property
@@ -158,10 +163,12 @@
cdef class CallDetails:
def __cinit__(self):
- grpc_call_details_init(&self.c_details)
+ with nogil:
+ grpc_call_details_init(&self.c_details)
def __dealloc__(self):
- grpc_call_details_destroy(&self.c_details)
+ with nogil:
+ grpc_call_details_destroy(&self.c_details)
@property
def method(self):
@@ -229,10 +236,15 @@
"ByteBuffer, not {}".format(type(data)))
cdef char *c_data = data
- data_slice = gpr_slice_from_copied_buffer(c_data, len(data))
- self.c_byte_buffer = grpc_raw_byte_buffer_create(
- &data_slice, 1)
- gpr_slice_unref(data_slice)
+ cdef gpr_slice data_slice
+ cdef size_t data_length = len(data)
+ with nogil:
+ data_slice = gpr_slice_from_copied_buffer(c_data, data_length)
+ with nogil:
+ self.c_byte_buffer = grpc_raw_byte_buffer_create(
+ &data_slice, 1)
+ with nogil:
+ gpr_slice_unref(data_slice)
def bytes(self):
cdef grpc_byte_buffer_reader reader
@@ -240,20 +252,27 @@
cdef size_t data_slice_length
cdef void *data_slice_pointer
if self.c_byte_buffer != NULL:
- grpc_byte_buffer_reader_init(&reader, self.c_byte_buffer)
+ with nogil:
+ grpc_byte_buffer_reader_init(&reader, self.c_byte_buffer)
result = b""
- while grpc_byte_buffer_reader_next(&reader, &data_slice):
- data_slice_pointer = gpr_slice_start_ptr(data_slice)
- data_slice_length = gpr_slice_length(data_slice)
- result += (<char *>data_slice_pointer)[:data_slice_length]
- grpc_byte_buffer_reader_destroy(&reader)
+ with nogil:
+ while grpc_byte_buffer_reader_next(&reader, &data_slice):
+ data_slice_pointer = gpr_slice_start_ptr(data_slice)
+ data_slice_length = gpr_slice_length(data_slice)
+ with gil:
+ result += (<char *>data_slice_pointer)[:data_slice_length]
+ with nogil:
+ grpc_byte_buffer_reader_destroy(&reader)
return result
else:
return None
def __len__(self):
+ cdef size_t result
if self.c_byte_buffer != NULL:
- return grpc_byte_buffer_length(self.c_byte_buffer)
+ with nogil:
+ result = grpc_byte_buffer_length(self.c_byte_buffer)
+ return result
else:
return 0
@@ -262,7 +281,8 @@
def __dealloc__(self):
if self.c_byte_buffer != NULL:
- grpc_byte_buffer_destroy(self.c_byte_buffer)
+ with nogil:
+ grpc_byte_buffer_destroy(self.c_byte_buffer)
cdef class SslPemKeyCertPair:
@@ -319,14 +339,15 @@
if not isinstance(arg, ChannelArg):
raise TypeError("expected list of ChannelArg")
self.c_args.arguments_length = len(self.args)
- self.c_args.arguments = <grpc_arg *>gpr_malloc(
- self.c_args.arguments_length*sizeof(grpc_arg)
- )
+ with nogil:
+ self.c_args.arguments = <grpc_arg *>gpr_malloc(
+ self.c_args.arguments_length*sizeof(grpc_arg))
for i in range(self.c_args.arguments_length):
self.c_args.arguments[i] = (<ChannelArg>self.args[i]).c_arg
def __dealloc__(self):
- gpr_free(self.c_args.arguments)
+ with nogil:
+ gpr_free(self.c_args.arguments)
def __len__(self):
# self.args is never stale; it's only updated from this file
@@ -407,21 +428,24 @@
for metadatum in metadata:
if not isinstance(metadatum, Metadatum):
raise TypeError("expected list of Metadatum")
- grpc_metadata_array_init(&self.c_metadata_array)
+ with nogil:
+ grpc_metadata_array_init(&self.c_metadata_array)
self.c_metadata_array.count = len(self.metadata)
self.c_metadata_array.capacity = len(self.metadata)
- self.c_metadata_array.metadata = <grpc_metadata *>gpr_malloc(
- self.c_metadata_array.count*sizeof(grpc_metadata)
- )
+ with nogil:
+ self.c_metadata_array.metadata = <grpc_metadata *>gpr_malloc(
+ self.c_metadata_array.count*sizeof(grpc_metadata)
+ )
for i in range(self.c_metadata_array.count):
self.c_metadata_array.metadata[i] = (
(<Metadatum>self.metadata[i]).c_metadata)
def __dealloc__(self):
# this frees the allocated memory for the grpc_metadata_array (although
- # it'd be nice if that were documented somewhere...) TODO(atash): document
- # this in the C core
- grpc_metadata_array_destroy(&self.c_metadata_array)
+ # it'd be nice if that were documented somewhere...)
+ # TODO(atash): document this in the C core
+ with nogil:
+ grpc_metadata_array_destroy(&self.c_metadata_array)
def __len__(self):
return self.c_metadata_array.count
@@ -526,7 +550,8 @@
# Python. The remaining one(s) are primitive fields filled in by GRPC core.
# This means that we need to clean up after receive_status_on_client.
if self.c_op.type == GRPC_OP_RECV_STATUS_ON_CLIENT:
- gpr_free(self._received_status_details)
+ with nogil:
+ gpr_free(self._received_status_details)
def operation_send_initial_metadata(Metadata metadata):
cdef Operation op = Operation()
@@ -648,8 +673,8 @@
if not isinstance(operation, Operation):
raise TypeError("expected operations to be iterable of Operation")
self.c_nops = len(self.operations)
- self.c_ops = <grpc_op *>gpr_malloc(
- sizeof(grpc_op)*self.c_nops)
+ with nogil:
+ self.c_ops = <grpc_op *>gpr_malloc(sizeof(grpc_op)*self.c_nops)
for i in range(self.c_nops):
self.c_ops[i] = (<Operation>(self.operations[i])).c_op
@@ -661,7 +686,8 @@
return self.operations[i]
def __dealloc__(self):
- gpr_free(self.c_ops)
+ with nogil:
+ gpr_free(self.c_ops)
def __iter__(self):
return _OperationsIterator(self)
diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi
index 5f85923..a098f11 100644
--- a/src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi
+++ b/src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi
@@ -41,7 +41,8 @@
if arguments is not None:
c_arguments = &arguments.c_args
self.references.append(arguments)
- self.c_server = grpc_server_create(c_arguments, NULL)
+ with nogil:
+ self.c_server = grpc_server_create(c_arguments, NULL)
self.is_started = False
self.is_shutting_down = False
self.is_shutdown = False
@@ -53,6 +54,7 @@
raise ValueError("server must be started and not shutting down")
if server_queue not in self.registered_completion_queues:
raise ValueError("server_queue must be a registered completion queue")
+ cdef grpc_call_error result
cdef OperationTag operation_tag = OperationTag(tag)
operation_tag.operation_call = Call()
operation_tag.request_call_details = CallDetails()
@@ -61,19 +63,22 @@
operation_tag.is_new_request = True
operation_tag.batch_operations = Operations([])
cpython.Py_INCREF(operation_tag)
- return grpc_server_request_call(
- self.c_server, &operation_tag.operation_call.c_call,
- &operation_tag.request_call_details.c_details,
- &operation_tag.request_metadata.c_metadata_array,
- call_queue.c_completion_queue, server_queue.c_completion_queue,
- <cpython.PyObject *>operation_tag)
+ with nogil:
+ result = grpc_server_request_call(
+ self.c_server, &operation_tag.operation_call.c_call,
+ &operation_tag.request_call_details.c_details,
+ &operation_tag.request_metadata.c_metadata_array,
+ call_queue.c_completion_queue, server_queue.c_completion_queue,
+ <cpython.PyObject *>operation_tag)
+ return result
def register_completion_queue(
self, CompletionQueue queue not None):
if self.is_started:
raise ValueError("cannot register completion queues after start")
- grpc_server_register_completion_queue(
- self.c_server, queue.c_completion_queue, NULL)
+ with nogil:
+ grpc_server_register_completion_queue(
+ self.c_server, queue.c_completion_queue, NULL)
self.registered_completion_queues.append(queue)
def start(self):
@@ -82,7 +87,8 @@
self.backup_shutdown_queue = CompletionQueue()
self.register_completion_queue(self.backup_shutdown_queue)
self.is_started = True
- grpc_server_start(self.c_server)
+ with nogil:
+ grpc_server_start(self.c_server)
# Ensure the core has gotten a chance to do the start-up work
self.backup_shutdown_queue.pluck(None, Timespec(None))
@@ -95,21 +101,28 @@
else:
raise TypeError("expected address to be a str or bytes")
self.references.append(address)
+ cdef int result
+ cdef char *address_c_string = address
if server_credentials is not None:
self.references.append(server_credentials)
- return grpc_server_add_secure_http2_port(
- self.c_server, address, server_credentials.c_credentials)
+ with nogil:
+ result = grpc_server_add_secure_http2_port(
+ self.c_server, address_c_string, server_credentials.c_credentials)
else:
- return grpc_server_add_insecure_http2_port(self.c_server, address)
+ with nogil:
+ result = grpc_server_add_insecure_http2_port(self.c_server,
+ address_c_string)
+ return result
cdef _c_shutdown(self, CompletionQueue queue, tag):
self.is_shutting_down = True
operation_tag = OperationTag(tag)
operation_tag.shutting_down_server = self
cpython.Py_INCREF(operation_tag)
- grpc_server_shutdown_and_notify(
- self.c_server, queue.c_completion_queue,
- <cpython.PyObject *>operation_tag)
+ with nogil:
+ grpc_server_shutdown_and_notify(
+ self.c_server, queue.c_completion_queue,
+ <cpython.PyObject *>operation_tag)
def shutdown(self, CompletionQueue queue not None, tag):
cdef OperationTag operation_tag
@@ -134,7 +147,8 @@
elif self.is_shutdown:
return
else:
- grpc_server_cancel_all_calls(self.c_server)
+ with nogil:
+ grpc_server_cancel_all_calls(self.c_server)
def __dealloc__(self):
if self.c_server != NULL:
@@ -153,5 +167,6 @@
# much but repeatedly release the GIL and wait
while not self.is_shutdown:
time.sleep(0)
- grpc_server_destroy(self.c_server)
+ with nogil:
+ grpc_server_destroy(self.c_server)
diff --git a/src/python/grpcio/grpc/_cython/cygrpc.pyx b/src/python/grpcio/grpc/_cython/cygrpc.pyx
index 30cc7a1..8a0f171 100644
--- a/src/python/grpcio/grpc/_cython/cygrpc.pyx
+++ b/src/python/grpcio/grpc/_cython/cygrpc.pyx
@@ -57,14 +57,17 @@
'grpc._cython', '_windows/grpc_c.64.python')
if not pygrpc_load_core(filename):
raise ImportError('failed to load core gRPC library')
- grpc_init()
+ with nogil:
+ grpc_init()
self.is_loaded = True
- grpc_set_ssl_roots_override_callback(
- <grpc_ssl_roots_override_callback>ssl_roots_override_callback)
+ with nogil:
+ grpc_set_ssl_roots_override_callback(
+ <grpc_ssl_roots_override_callback>ssl_roots_override_callback)
def __dealloc__(self):
if self.is_loaded:
- grpc_shutdown()
+ with nogil:
+ grpc_shutdown()
_module_state = _ModuleState()
diff --git a/src/python/grpcio/tests/_runner.py b/src/python/grpcio/tests/_runner.py
index b0dbd92..32a31ce 100644
--- a/src/python/grpcio/tests/_runner.py
+++ b/src/python/grpcio/tests/_runner.py
@@ -43,6 +43,13 @@
from tests import _loader
from tests import _result
+# This number needs to be large enough to outpace output on stdout and stderr
+# from the gRPC core, otherwise we could end up in a potential deadlock. This
+# stems from the OS waiting on someone to clear a filled pipe buffer while the
+# GIL is held from a write to stderr from gRPC core, but said someone is in
+# Python code thus necessitating GIL acquisition.
+_READ_BYTES = 2**20
+
class CapturePipe(object):
"""A context-manager pipe to redirect output to a byte array.
@@ -76,6 +83,10 @@
flags = fcntl.fcntl(self._read_fd, fcntl.F_GETFL)
fcntl.fcntl(self._read_fd, fcntl.F_SETFL, flags | os.O_NONBLOCK)
self._read_thread = threading.Thread(target=self._read)
+ # If the user wants to exit from the Python program and hits ctrl-C and the
+ # read thread is somehow deadlocked with something else, the Python code may
+ # refuse to exit. This prevents that by making the read thread second-class.
+ self._read_thread.daemon = True
self._read_thread.start()
def stop(self):
@@ -93,7 +104,7 @@
self.output = bytearray()
while True:
select.select([self._read_fd], [], [])
- read_bytes = os.read(self._read_fd, 1024)
+ read_bytes = os.read(self._read_fd, _READ_BYTES)
if read_bytes:
self.output.extend(read_bytes)
else:
diff --git a/test/core/util/port_posix.c b/test/core/util/port_posix.c
index ba382d2..c4bd00c 100644
--- a/test/core/util/port_posix.c
+++ b/test/core/util/port_posix.c
@@ -77,6 +77,7 @@
static void destroy_pollset_and_shutdown(grpc_exec_ctx *exec_ctx, void *p,
bool success) {
grpc_pollset_destroy(p);
+ gpr_free(p);
grpc_shutdown();
}
@@ -95,7 +96,7 @@
freereq pr;
char *path;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_closure shutdown_closure;
+ grpc_closure *shutdown_closure;
grpc_init();
@@ -104,8 +105,8 @@
pr.pollset = gpr_malloc(grpc_pollset_size());
grpc_pollset_init(pr.pollset, &pr.mu);
- grpc_closure_init(&shutdown_closure, destroy_pollset_and_shutdown,
- pr.pollset);
+ shutdown_closure =
+ grpc_closure_create(destroy_pollset_and_shutdown, pr.pollset);
req.host = server;
gpr_asprintf(&path, "/drop/%d", port);
@@ -126,9 +127,8 @@
grpc_httpcli_context_destroy(&context);
grpc_exec_ctx_finish(&exec_ctx);
- grpc_pollset_shutdown(&exec_ctx, pr.pollset, &shutdown_closure);
+ grpc_pollset_shutdown(&exec_ctx, pr.pollset, shutdown_closure);
grpc_exec_ctx_finish(&exec_ctx);
- gpr_free(pr.pollset);
gpr_free(path);
}
@@ -262,7 +262,7 @@
grpc_httpcli_request req;
portreq pr;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_closure shutdown_closure;
+ grpc_closure *shutdown_closure;
grpc_init();
@@ -270,8 +270,8 @@
memset(&req, 0, sizeof(req));
pr.pollset = gpr_malloc(grpc_pollset_size());
grpc_pollset_init(pr.pollset, &pr.mu);
- grpc_closure_init(&shutdown_closure, destroy_pollset_and_shutdown,
- pr.pollset);
+ shutdown_closure =
+ grpc_closure_create(destroy_pollset_and_shutdown, pr.pollset);
pr.port = -1;
pr.server = server;
pr.ctx = &context;
@@ -294,9 +294,8 @@
gpr_mu_unlock(pr.mu);
grpc_httpcli_context_destroy(&context);
- grpc_pollset_shutdown(&exec_ctx, pr.pollset, &shutdown_closure);
+ grpc_pollset_shutdown(&exec_ctx, pr.pollset, shutdown_closure);
grpc_exec_ctx_finish(&exec_ctx);
- gpr_free(pr.pollset);
return pr.port;
}
diff --git a/test/core/util/test_config.c b/test/core/util/test_config.c
index 14bfc95..bf672e8 100644
--- a/test/core/util/test_config.c
+++ b/test/core/util/test_config.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -33,11 +33,13 @@
#include "test/core/util/test_config.h"
-#include <grpc/support/port_platform.h>
#include <grpc/support/log.h>
-#include "src/core/support/string.h"
-#include <stdlib.h>
+#include <grpc/support/port_platform.h>
#include <signal.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "src/core/support/string.h"
double g_fixture_slowdown_factor = 1.0;
@@ -52,14 +54,125 @@
#endif
#if GPR_WINDOWS_CRASH_HANDLER
-LONG crash_handler(struct _EXCEPTION_POINTERS *ex_info) {
- gpr_log(GPR_DEBUG, "Exception handler called, dumping information");
- while (ex_info->ExceptionRecord) {
- DWORD code = ex_info->ExceptionRecord->ExceptionCode;
- DWORD flgs = ex_info->ExceptionRecord->ExceptionFlags;
- PVOID addr = ex_info->ExceptionRecord->ExceptionAddress;
- gpr_log("code: %x - flags: %d - address: %p", code, flgs, addr);
- ex_info->ExceptionRecord = ex_info->ExceptionRecord->ExceptionRecord;
+#include <windows.h>
+
+#include <tchar.h>
+
+// disable warning 4091 - dbghelp.h is broken for msvc2015
+#pragma warning(disable : 4091)
+#define DBGHELP_TRANSLATE_TCHAR
+#include <dbghelp.h>
+
+#ifdef _MSC_VER
+#pragma comment(lib, "dbghelp.lib")
+#endif
+
+static void print_current_stack() {
+ typedef USHORT(WINAPI * CaptureStackBackTraceType)(
+ __in ULONG, __in ULONG, __out PVOID *, __out_opt PULONG);
+ CaptureStackBackTraceType func = (CaptureStackBackTraceType)(GetProcAddress(
+ LoadLibrary(_T("kernel32.dll")), "RtlCaptureStackBackTrace"));
+
+ if (func == NULL) return; // WOE 29.SEP.2010
+
+// Quote from Microsoft Documentation:
+// ## Windows Server 2003 and Windows XP:
+// ## The sum of the FramesToSkip and FramesToCapture parameters must be less
+// than 63.
+#define MAX_CALLERS 62
+
+ void *callers_stack[MAX_CALLERS];
+ unsigned short frames;
+ SYMBOL_INFOW *symbol;
+ HANDLE process;
+ process = GetCurrentProcess();
+ SymInitialize(process, NULL, TRUE);
+ frames = (func)(0, MAX_CALLERS, callers_stack, NULL);
+ symbol =
+ (SYMBOL_INFOW *)calloc(sizeof(SYMBOL_INFOW) + 256 * sizeof(wchar_t), 1);
+ symbol->MaxNameLen = 255;
+ symbol->SizeOfStruct = sizeof(SYMBOL_INFOW);
+
+ const unsigned short MAX_CALLERS_SHOWN = 32;
+ frames = frames < MAX_CALLERS_SHOWN ? frames : MAX_CALLERS_SHOWN;
+ for (unsigned int i = 0; i < frames; i++) {
+ SymFromAddrW(process, (DWORD64)(callers_stack[i]), 0, symbol);
+ fwprintf(stderr, L"*** %d: %016I64X %ls - %016I64X\n", i,
+ (DWORD64)callers_stack[i], symbol->Name, (DWORD64)symbol->Address);
+ }
+
+ free(symbol);
+}
+
+static void print_stack_from_context(CONTEXT c) {
+ STACKFRAME s; // in/out stackframe
+ memset(&s, 0, sizeof(s));
+ DWORD imageType;
+#ifdef _M_IX86
+ // normally, call ImageNtHeader() and use machine info from PE header
+ imageType = IMAGE_FILE_MACHINE_I386;
+ s.AddrPC.Offset = c.Eip;
+ s.AddrPC.Mode = AddrModeFlat;
+ s.AddrFrame.Offset = c.Ebp;
+ s.AddrFrame.Mode = AddrModeFlat;
+ s.AddrStack.Offset = c.Esp;
+ s.AddrStack.Mode = AddrModeFlat;
+#elif _M_X64
+ imageType = IMAGE_FILE_MACHINE_AMD64;
+ s.AddrPC.Offset = c.Rip;
+ s.AddrPC.Mode = AddrModeFlat;
+ s.AddrFrame.Offset = c.Rsp;
+ s.AddrFrame.Mode = AddrModeFlat;
+ s.AddrStack.Offset = c.Rsp;
+ s.AddrStack.Mode = AddrModeFlat;
+#elif _M_IA64
+ imageType = IMAGE_FILE_MACHINE_IA64;
+ s.AddrPC.Offset = c.StIIP;
+ s.AddrPC.Mode = AddrModeFlat;
+ s.AddrFrame.Offset = c.IntSp;
+ s.AddrFrame.Mode = AddrModeFlat;
+ s.AddrBStore.Offset = c.RsBSP;
+ s.AddrBStore.Mode = AddrModeFlat;
+ s.AddrStack.Offset = c.IntSp;
+ s.AddrStack.Mode = AddrModeFlat;
+#else
+#error "Platform not supported!"
+#endif
+
+ HANDLE process = GetCurrentProcess();
+ HANDLE thread = GetCurrentThread();
+
+ SYMBOL_INFOW *symbol =
+ (SYMBOL_INFOW *)calloc(sizeof(SYMBOL_INFOW) + 256 * sizeof(wchar_t), 1);
+ symbol->MaxNameLen = 255;
+ symbol->SizeOfStruct = sizeof(SYMBOL_INFOW);
+
+ while (StackWalk(imageType, process, thread, &s, &c, 0,
+ SymFunctionTableAccess, SymGetModuleBase, 0)) {
+ BOOL has_symbol =
+ SymFromAddrW(process, (DWORD64)(s.AddrPC.Offset), 0, symbol);
+ fwprintf(
+ stderr, L"*** %016I64X %ls - %016I64X\n", (DWORD64)(s.AddrPC.Offset),
+ has_symbol ? symbol->Name : L"<<no symbol>>", (DWORD64)symbol->Address);
+ }
+
+ free(symbol);
+}
+
+static LONG crash_handler(struct _EXCEPTION_POINTERS *ex_info) {
+ fprintf(stderr, "Exception handler called, dumping information\n");
+ bool try_to_print_stack = true;
+ PEXCEPTION_RECORD exrec = ex_info->ExceptionRecord;
+ while (exrec) {
+ DWORD code = exrec->ExceptionCode;
+ DWORD flgs = exrec->ExceptionFlags;
+ PVOID addr = exrec->ExceptionAddress;
+ if (code == EXCEPTION_STACK_OVERFLOW) try_to_print_stack = false;
+ fprintf(stderr, "code: %x - flags: %d - address: %p\n", code, flgs, addr);
+ exrec = exrec->ExceptionRecord;
+ }
+ if (try_to_print_stack) {
+ print_stack_from_context(*ex_info->ContextRecord);
}
if (IsDebuggerPresent()) {
__debugbreak();
@@ -69,8 +182,9 @@
return EXCEPTION_EXECUTE_HANDLER;
}
-void abort_handler(int sig) {
- gpr_log(GPR_DEBUG, "Abort handler called.");
+static void abort_handler(int sig) {
+ fprintf(stderr, "Abort handler called.\n");
+ print_current_stack(NULL);
if (IsDebuggerPresent()) {
__debugbreak();
} else {
@@ -79,17 +193,20 @@
}
static void install_crash_handler() {
+ if (!SymInitialize(GetCurrentProcess(), NULL, TRUE)) {
+ fprintf(stderr, "SymInitialize failed: %d\n", GetLastError());
+ }
SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)crash_handler);
_set_abort_behavior(0, _WRITE_ABORT_MSG);
_set_abort_behavior(0, _CALL_REPORTFAULT);
signal(SIGABRT, abort_handler);
}
#elif GPR_POSIX_CRASH_HANDLER
+#include <errno.h>
#include <execinfo.h>
+#include <grpc/support/useful.h>
#include <stdio.h>
#include <string.h>
-#include <grpc/support/useful.h>
-#include <errno.h>
static char g_alt_stack[MINSIGSTKSZ];
diff --git a/tools/README.md b/tools/README.md
index df4c6ef..cb6c22d 100644
--- a/tools/README.md
+++ b/tools/README.md
@@ -1,13 +1,16 @@
-buildgen: template renderer for our build system.
+buildgen: Template renderer for our build system.
-distrib: scripts to distribute language-specific packages.
+distrib: Scripts to distribute language-specific packages.
dockerfile: Docker files to test gRPC.
doxygen: gRPC C/C++ documentation generation via Doxygen.
-gce: scripts to help setup testing infrastructure on GCE.
+gce: Scripts to help setup testing infrastructure on GCE.
-jenkins: support for running tests on Jenkins.
+gcp: Helper scripts for interacting with various services on GCP (like Google
+container engine, BigQuery etc)
-run_tests: scripts to run gRPC tests in parallel.
+jenkins: Support for running tests on Jenkins.
+
+run_tests: Scripts to run gRPC tests in parallel.
diff --git a/tools/jenkins/run_full_interop.sh b/tools/jenkins/run_full_interop.sh
old mode 100644
new mode 100755
diff --git a/tools/run_tests/configs.json b/tools/run_tests/configs.json
index cbb8ec5..a858170 100644
--- a/tools/run_tests/configs.json
+++ b/tools/run_tests/configs.json
@@ -3,6 +3,29 @@
"config": "opt"
},
{
+ "config": "dbg"
+ },
+ {
+ "config": "easan",
+ "environ": {
+ "ASAN_OPTIONS": "detect_leaks=1:color=always",
+ "LSAN_OPTIONS": "suppressions=tools/lsan_suppressions.txt:report_objects=1"
+ },
+ "timeout_multiplier": 3
+ },
+ {
+ "config": "asan",
+ "environ": {
+ "ASAN_OPTIONS": "detect_leaks=1:color=always",
+ "LSAN_OPTIONS": "suppressions=tools/lsan_suppressions.txt:report_objects=1"
+ },
+ "timeout_multiplier": 3
+ },
+ {
+ "config": "msan",
+ "timeout_multiplier": 4
+ },
+ {
"config": "basicprof"
},
{
@@ -21,17 +44,24 @@
"timeout_multiplier": 3
},
{
+ "config": "edbg"
+ },
+ {
"config": "ubsan",
"timeout_multiplier": 1.5
},
{
- "config": "dbg"
+ "config": "tsan",
+ "environ": {
+ "TSAN_OPTIONS": "suppressions=tools/tsan_suppressions.txt:halt_on_error=1:second_deadlock_stack=1"
+ },
+ "timeout_multiplier": 5
},
{
"config": "stapprof"
},
{
- "config": "gcov"
+ "config": "mutrace"
},
{
"config": "memcheck",
@@ -43,25 +73,13 @@
]
},
{
- "config": "asan",
- "environ": {
- "ASAN_OPTIONS": "detect_leaks=1:color=always",
- "LSAN_OPTIONS": "suppressions=tools/lsan_suppressions.txt:report_objects=1"
- },
- "timeout_multiplier": 3
- },
- {
- "config": "tsan",
+ "config": "etsan",
"environ": {
"TSAN_OPTIONS": "suppressions=tools/tsan_suppressions.txt:halt_on_error=1:second_deadlock_stack=1"
},
"timeout_multiplier": 5
},
{
- "config": "msan",
- "timeout_multiplier": 4
- },
- {
- "config": "mutrace"
+ "config": "gcov"
}
]
diff --git a/tools/run_tests/stress_test/README.md b/tools/run_tests/stress_test/README.md
new file mode 100644
index 0000000..80e4cd5
--- /dev/null
+++ b/tools/run_tests/stress_test/README.md
@@ -0,0 +1,53 @@
+Running Stress tests on Google Container Engine
+=======================================
+
+### **Glossary**:
+* GCP: Google Cloud Platform
+* GCE: Google Compute Engine
+* GKE: Google Container Engine
+* GCP console: https://console.cloud.google.com
+
+### **Setup Instructions**
+#### *On GCP:*
+1. Login to GCP with your Google account (for example, your @gmail account) at https://cloud.google.com. If do not have a Google account, you will have to create an account first.
+2. Enable billing on Google cloud platform. Instructions [here](https://cloud.google.com/container-engine/docs/before-you-begin) (see the '*Enable billing*' section).
+3. Create a Project from the [GCP console](https://console.cloud.google.com).i.e Click on the project dropdown box on the top right (to the right of the search box) and click '*Create a project*' option.
+4. Enable the Container Engine API. Instructions [here](https://cloud.google.com/container-engine/docs/before-you-begin) (See the '*Enable the Container Engine API*’ section). Alternatively, you can do the following:
+ - Click on the '*Products & Services*' icon on the top left (i.e the icon with three small horizontal bars) and select '*API Manager*'
+ - Select the '*Container Engine API*' under '*Google Cloud APIs*' on the main page. Note that you might have to click on '*More*' under '*Google Cloud APIs*' to see the '*Container Engine API*' link
+ - Click on the '*Enable*' button. If the API is already enabled, the button's label would be '*Disable*' instead (do NOT click the button if its label is '*Disable*')
+5. Create a Cluster from the GCP console.
+ - Go to the Container Engine section from GCP console i.e: Click on the '*Products & Services*' icon on the top left (i.e the icon with three small horizontal bars) and click on '*Container Engine*'
+ - Click '*Create Container Cluster*' and follow the instructions.
+ - The instructions for 'Name/Zone/MachineType' etc are [here](https://cloud.google.com/container-engine/docs/clusters/operations) (**NOTE**: The page also has instructions to setting up default clusters and configuring `kubectl`. We will be doing that later)
+ - For the cluster size, a smaller size of < 10 GCE instances is good enough for our use cases - assuming that we are planning to run a reasonably small number of stress client instances. For the machine type, something like '2 vCPUs 7.5 GB' (available in the drop down box) should be good enough.
+ - **IMPORTANT**: Before hitting the '*Create*' button, click on '*More*' link just above the '*Create*' button and Select '*Enabled*' for BigQuery , '*Enabled*' for Cloud Platform and '*Read/Write*' for Cloud User Accounts.
+ - Create the cluster by clicking '*Create*' button.
+
+#### *On your machine* (or the machine from which stress tests on GKE are launched):
+1. You need a working gRPC repository on your machine. If you do not have it, clone the grpc repository from github (https://github.com/grpc/grpc) and follow the instructions [here](https://github.com/grpc/grpc/blob/master/INSTALL.md)
+2. Install Docker. Instructions [here](https://docs.docker.com/engine/installation/)
+3. Install Google Cloud SDK. Instructions [here](https://cloud.google.com/sdk/). This installs the `gcloud` tool
+4. Install `kubectl`, Kubernetes command line tool using `gcloud`. i.e
+ - `$ gcloud components update kubectl`
+5. Install Google python client apis:
+ - `‘$ sudo pip install --upgrade google-api-python-client’`
+ - **Note**: Do `$ sudo apt-get install python-pip` (or `$ easy_install -U pip`) if you do not have pip
+6. Install the `requests` Python package if you don’t have it already by doing `sudo pip install requests`. More details regarding `requests` package are [here](http://docs.python-requests.org/en/master/user/install/)
+7. Set the `gcloud` defaults: See the instructions [here](https://cloud.google.com/container-engine/docs/before-you-begin) under "*Set gcloud defaults*" section)
+ - Make sure you also fetch the cluster credentials for `kubectl` command to use. I.e `$ gcloud container clusters get-credentials CLUSTER_NAME`
+
+### **Launching Stress tests**
+
+The stress tests are launched by the following script (path is relative to GRPC root directory) :
+`tools/run_tests/stress_test/run_stress_tests_on_gke.py`
+
+The script has several parameters and you can find out more details by using the `--help` flag.
+ - `<grpc_root_dir>$ tools/run_tests/stress_test/run_stress_tests_on_gke.py --help`
+
+> **Example**
+> `$ tools/run_tests/stress_test/run_stress_tests_on_gke.py --project_id=sree-gce --test_duration_secs=180 --num_clients=5`
+
+> Launches the 5 instances of stress test clients, 1 instance of stress test server and runs the test for 180 seconds. The test would be run on the default container cluster (that you have set in `gcloud`) in the project `sree-gce`.
+
+> Note: we currently do not have the ability to launch multiple instances of the server. This can be added very easily in future