From 570d808d61d194c322c324f73514e804f8d80a2e Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Thu, 16 Jan 2020 14:16:24 -0800 Subject: [PATCH] Log (in debug mode) if CQ destroyed without full draining --- src/core/lib/surface/completion_queue.cc | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/core/lib/surface/completion_queue.cc b/src/core/lib/surface/completion_queue.cc index 49d72b5e6d7..60cbb244678 100644 --- a/src/core/lib/surface/completion_queue.cc +++ b/src/core/lib/surface/completion_queue.cc @@ -241,7 +241,14 @@ class CqEventQueue { }; struct cq_next_data { - ~cq_next_data() { GPR_ASSERT(queue.num_items() == 0); } + ~cq_next_data() { + GPR_ASSERT(queue.num_items() == 0); +#ifndef NDEBUG + if (pending_events.Load(grpc_core::MemoryOrder::ACQUIRE) != 0) { + gpr_log(GPR_ERROR, "Destroying CQ without draining it fully."); + } +#endif + } /** Completed events for completion-queues of type GRPC_CQ_NEXT */ CqEventQueue queue; @@ -267,6 +274,11 @@ struct cq_pluck_data { ~cq_pluck_data() { GPR_ASSERT(completed_head.next == reinterpret_cast(&completed_head)); +#ifndef NDEBUG + if (pending_events.Load(grpc_core::MemoryOrder::ACQUIRE) != 0) { + gpr_log(GPR_ERROR, "Destroying CQ without draining it fully."); + } +#endif } /** Completed events for completion-queues of type GRPC_CQ_PLUCK */ @@ -298,6 +310,15 @@ struct cq_callback_data { cq_callback_data( grpc_experimental_completion_queue_functor* shutdown_callback) : shutdown_callback(shutdown_callback) {} + + ~cq_callback_data() { +#ifndef NDEBUG + if (pending_events.Load(grpc_core::MemoryOrder::ACQUIRE) != 0) { + gpr_log(GPR_ERROR, "Destroying CQ without draining it fully."); + } +#endif + } + /** No actual completed events queue, unlike other types */ /** Number of pending events (+1 if we're not shutdown).