diff --git a/src/core/lib/iomgr/closure.c b/src/core/lib/iomgr/closure.c index da0ec878a39818bc5b5fcfd5ec7935f09e8efa0d..8e4efd3370d977819fb82359bf69ea2f5c6f3531 100644 --- a/src/core/lib/iomgr/closure.c +++ b/src/core/lib/iomgr/closure.c @@ -34,6 +34,7 @@ #include "src/core/lib/iomgr/closure.h" #include <grpc/support/alloc.h> +#include <grpc/support/log.h> #include "src/core/lib/profiling/timers.h" diff --git a/src/core/lib/iomgr/closure.h b/src/core/lib/iomgr/closure.h index ee386fbc7670c28b94c26b5d2cc8dab8f882fbe7..6748b21e59c6b44b21f5589af348cfa2090c1a4c 100644 --- a/src/core/lib/iomgr/closure.h +++ b/src/core/lib/iomgr/closure.h @@ -66,6 +66,7 @@ typedef struct grpc_closure_scheduler_vtable { grpc_error *error); void (*sched)(grpc_exec_ctx *exec_ctx, grpc_closure *closure, grpc_error *error); + const char *name; } grpc_closure_scheduler_vtable; /** Abstract type that can schedule closures for execution */ diff --git a/src/core/lib/iomgr/combiner.c b/src/core/lib/iomgr/combiner.c index c26a73b2b716a0d6316703ad5410b55113dde78c..ba6c7087a920cb5339346e67853b013e1237ed45 100644 --- a/src/core/lib/iomgr/combiner.c +++ b/src/core/lib/iomgr/combiner.c @@ -86,13 +86,17 @@ static void combiner_finally_exec_covered(grpc_exec_ctx *exec_ctx, grpc_error *error); static const grpc_closure_scheduler_vtable scheduler_uncovered = { - combiner_exec_uncovered, combiner_exec_uncovered}; + combiner_exec_uncovered, combiner_exec_uncovered, + "combiner:immediately:uncovered"}; static const grpc_closure_scheduler_vtable scheduler_covered = { - combiner_exec_covered, combiner_exec_covered}; + combiner_exec_covered, combiner_exec_covered, + "combiner:immediately:covered"}; static const grpc_closure_scheduler_vtable finally_scheduler_uncovered = { - combiner_finally_exec_uncovered, combiner_finally_exec_uncovered}; + combiner_finally_exec_uncovered, combiner_finally_exec_uncovered, + "combiner:finally:uncovered"}; static const grpc_closure_scheduler_vtable finally_scheduler_covered = { - combiner_finally_exec_covered, combiner_finally_exec_covered}; + combiner_finally_exec_covered, combiner_finally_exec_covered, + "combiner:finally:covered"}; static void offload(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error); diff --git a/src/core/lib/iomgr/ev_epoll_linux.c b/src/core/lib/iomgr/ev_epoll_linux.c index d6664aead2e56f13d27c2037f2178abc787f4578..39b5c0032e8138d92657d73549060590608c3562 100644 --- a/src/core/lib/iomgr/ev_epoll_linux.c +++ b/src/core/lib/iomgr/ev_epoll_linux.c @@ -321,7 +321,7 @@ gpr_atm g_epoll_sync; #endif /* defined(GRPC_TSAN) */ static const grpc_closure_scheduler_vtable workqueue_scheduler_vtable = { - workqueue_enqueue, workqueue_enqueue}; + workqueue_enqueue, workqueue_enqueue, "workqueue"}; static void pi_add_ref(polling_island *pi); static void pi_unref(grpc_exec_ctx *exec_ctx, polling_island *pi); diff --git a/src/core/lib/iomgr/exec_ctx.c b/src/core/lib/iomgr/exec_ctx.c index 6aa788f8e5f981f4af6259b12843ca5f2925be2d..fabe6c6988799d56a2748ab93891f4f374677c62 100644 --- a/src/core/lib/iomgr/exec_ctx.c +++ b/src/core/lib/iomgr/exec_ctx.c @@ -101,6 +101,6 @@ void grpc_exec_ctx_global_init(void) {} void grpc_exec_ctx_global_shutdown(void) {} static const grpc_closure_scheduler_vtable exec_ctx_scheduler_vtable = { - exec_ctx_run, exec_ctx_sched}; + exec_ctx_run, exec_ctx_sched, "exec_ctx"}; static grpc_closure_scheduler exec_ctx_scheduler = {&exec_ctx_scheduler_vtable}; grpc_closure_scheduler *grpc_schedule_on_exec_ctx = &exec_ctx_scheduler; diff --git a/src/core/lib/iomgr/executor.c b/src/core/lib/iomgr/executor.c index 852775564f6c95bc8a77c659cbcad3fa28d2178c..a5b62aa88885ccce3c0f89bb8fc0a945f80e63c4 100644 --- a/src/core/lib/iomgr/executor.c +++ b/src/core/lib/iomgr/executor.c @@ -158,7 +158,7 @@ void grpc_executor_shutdown(grpc_exec_ctx *exec_ctx) { gpr_mu_destroy(&g_executor.mu); } -static const grpc_closure_scheduler_vtable executor_vtable = {executor_push, - executor_push}; +static const grpc_closure_scheduler_vtable executor_vtable = { + executor_push, executor_push, "executor"}; static grpc_closure_scheduler executor_scheduler = {&executor_vtable}; grpc_closure_scheduler *grpc_executor_scheduler = &executor_scheduler; diff --git a/src/core/lib/security/credentials/plugin/plugin_credentials.c b/src/core/lib/security/credentials/plugin/plugin_credentials.c index c5e8d67039d4c7a32da06353f55cba7db0f4bc50..afce6a6b12ce4211eb3eb9bdad7cd1209b619008 100644 --- a/src/core/lib/security/credentials/plugin/plugin_credentials.c +++ b/src/core/lib/security/credentials/plugin/plugin_credentials.c @@ -44,6 +44,7 @@ #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/surface/api_trace.h" +#include "src/core/lib/surface/validate_metadata.h" typedef struct { void *user_data; @@ -78,14 +79,14 @@ static void plugin_md_request_metadata_ready(void *request, bool seen_illegal_header = false; grpc_credentials_md *md_array = NULL; for (i = 0; i < num_md; i++) { - if (!grpc_header_key_is_legal(md[i].key)) { - char *key = grpc_slice_to_c_string(md[i].key); - gpr_log(GPR_ERROR, "Plugin added invalid metadata key: %s", key); - gpr_free(key); + if (!GRPC_LOG_IF_ERROR("validate_metadata_from_plugin", + grpc_validate_header_key_is_legal(md[i].key))) { seen_illegal_header = true; break; } else if (!grpc_is_binary_header(md[i].key) && - !grpc_header_nonbin_value_is_legal(md[i].value)) { + !GRPC_LOG_IF_ERROR( + "validate_metadata_from_plugin", + grpc_validate_header_nonbin_value_is_legal(md[i].value))) { gpr_log(GPR_ERROR, "Plugin added invalid metadata value."); seen_illegal_header = true; break; diff --git a/src/core/lib/security/transport/client_auth_filter.c b/src/core/lib/security/transport/client_auth_filter.c index cf7de493458eeabffb4426662d19387027bfdfc7..cf056e80080a9614b2d3c7f70916ef178b42a231 100644 --- a/src/core/lib/security/transport/client_auth_filter.c +++ b/src/core/lib/security/transport/client_auth_filter.c @@ -123,24 +123,12 @@ static void on_credentials_metadata(grpc_exec_ctx *exec_ctx, void *user_data, GPR_ASSERT(op->send_initial_metadata != NULL); mdb = op->send_initial_metadata; for (i = 0; i < num_md; i++) { - if (!grpc_header_key_is_legal(md_elems[i].key)) { - char *str = grpc_slice_to_c_string(md_elems[i].key); - gpr_log(GPR_ERROR, "attempt to send invalid metadata key: %s", str); - gpr_free(str); - } else if (!grpc_is_binary_header(md_elems[i].key) && - !grpc_header_nonbin_value_is_legal(md_elems[i].value)) { - char *str = - grpc_dump_slice(md_elems[i].value, GPR_DUMP_HEX | GPR_DUMP_ASCII); - gpr_log(GPR_ERROR, "attempt to send invalid metadata value: %s", str); - gpr_free(str); - } else { - add_error(&error, - grpc_metadata_batch_add_tail( - exec_ctx, mdb, &calld->md_links[i], - grpc_mdelem_from_slices( - exec_ctx, grpc_slice_ref_internal(md_elems[i].key), - grpc_slice_ref_internal(md_elems[i].value)))); - } + add_error(&error, + grpc_metadata_batch_add_tail( + exec_ctx, mdb, &calld->md_links[i], + grpc_mdelem_from_slices( + exec_ctx, grpc_slice_ref_internal(md_elems[i].key), + grpc_slice_ref_internal(md_elems[i].value)))); } } if (error == GRPC_ERROR_NONE) { diff --git a/src/cpp/client/secure_credentials.h b/src/cpp/client/secure_credentials.h index 281db17e98303f43353bf3bd568b8f2cdd9b24bb..713654ad5ba79e4d9ad5de248a3a47f7b1c99303 100644 --- a/src/cpp/client/secure_credentials.h +++ b/src/cpp/client/secure_credentials.h @@ -70,7 +70,7 @@ class SecureCallCredentials final : public CallCredentials { grpc_call_credentials* const c_creds_; }; -class MetadataCredentialsPluginWrapper final { +class MetadataCredentialsPluginWrapper final : private GrpcLibraryCodegen { public: static void Destroy(void* wrapper); static void GetMetadata(void* wrapper, grpc_auth_metadata_context context, diff --git a/src/cpp/server/dynamic_thread_pool.cc b/src/cpp/server/dynamic_thread_pool.cc index 1fdc2edb2594f753ee4f31e6314f3b6c0e90c8d8..e7721bc990260855681be353e4f094e9b9eb19b7 100644 --- a/src/cpp/server/dynamic_thread_pool.cc +++ b/src/cpp/server/dynamic_thread_pool.cc @@ -31,12 +31,16 @@ * */ +#include "src/cpp/server/dynamic_thread_pool.h" + #include <mutex> #include <thread> -#include "src/cpp/server/dynamic_thread_pool.h" +#include <grpc/support/log.h> namespace grpc { +static thread_local bool g_is_dynamic_thread_pool_thread; + DynamicThreadPool::DynamicThread::DynamicThread(DynamicThreadPool* pool) : pool_(pool), thd_(new std::thread(&DynamicThreadPool::DynamicThread::ThreadFunc, @@ -47,6 +51,7 @@ DynamicThreadPool::DynamicThread::~DynamicThread() { } void DynamicThreadPool::DynamicThread::ThreadFunc() { + g_is_dynamic_thread_pool_thread = true; pool_->ThreadFunc(); // Now that we have killed ourselves, we should reduce the thread count std::unique_lock<std::mutex> lock(pool_->mu_); @@ -99,11 +104,13 @@ DynamicThreadPool::DynamicThreadPool(int reserve_threads) void DynamicThreadPool::ReapThreads(std::list<DynamicThread*>* tlist) { for (auto t = tlist->begin(); t != tlist->end(); t = tlist->erase(t)) { + gpr_log(GPR_DEBUG, "delete %p", *t); delete *t; } } DynamicThreadPool::~DynamicThreadPool() { + GPR_ASSERT(!g_is_dynamic_thread_pool_thread); std::unique_lock<std::mutex> lock(mu_); shutdown_ = true; cv_.notify_all(); diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index 620b3ae7bcb9e58dc85c8a5e2530779de53cf023..dff5c3d9ecddbc007dc9b67378bda688e2abca6d 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -1302,6 +1302,7 @@ TEST_P(SecureEnd2endTest, BlockingAuthMetadataPluginAndProcessorFailure) { EXPECT_FALSE(s.ok()); EXPECT_EQ(s.error_code(), StatusCode::UNAUTHENTICATED); } + TEST_P(SecureEnd2endTest, SetPerCallCredentials) { ResetStub(); EchoRequest request;