From 694e4b84272148cab34334aa575055530ec1fb05 Mon Sep 17 00:00:00 2001 From: Alisha Nanda Date: Wed, 23 Nov 2022 14:46:50 -0800 Subject: [PATCH] Add more info to metadata limit exceeded error (#31756) * Add more info to error * Fix tests --- .../ext/transport/chttp2/transport/hpack_parser.cc | 14 +++++++------- test/core/end2end/tests/large_metadata.cc | 7 +++++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.cc b/src/core/ext/transport/chttp2/transport/hpack_parser.cc index 8d7c0996acc..a62602c8f2b 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.cc @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -1190,16 +1191,15 @@ class HPackParser::Parser { GPR_ATTRIBUTE_NOINLINE bool HandleMetadataSizeLimitExceeded(const HPackTable::Memento&) { - gpr_log(GPR_DEBUG, - "received initial metadata size exceeds limit (%" PRIu32 - " vs. %" PRIu32 - "). GRPC_ARG_MAX_METADATA_SIZE can be set to increase this limit.", - *frame_length_, metadata_size_limit_); if (metadata_buffer_ != nullptr) metadata_buffer_->Clear(); + // TODO(alishananda): add debug log with metadata details return input_->MaybeSetErrorAndReturn( - [] { + [this] { return grpc_error_set_int( - GRPC_ERROR_CREATE("received initial metadata size exceeds limit"), + GRPC_ERROR_CREATE(absl::StrFormat( + "received initial metadata size exceeds limit (%" PRIu32 + " vs. %" PRIu32 ")", + *frame_length_, metadata_size_limit_)), StatusIntProperty::kRpcStatus, GRPC_STATUS_RESOURCE_EXHAUSTED); }, false); diff --git a/test/core/end2end/tests/large_metadata.cc b/test/core/end2end/tests/large_metadata.cc index ebebddba87a..50f61dcbf09 100644 --- a/test/core/end2end/tests/large_metadata.cc +++ b/test/core/end2end/tests/large_metadata.cc @@ -353,10 +353,13 @@ static void test_request_with_bad_large_metadata_response( cqv.Verify(); GPR_ASSERT(status == GRPC_STATUS_RESOURCE_EXHAUSTED); - GPR_ASSERT(0 == grpc_slice_str_cmp( - details, "received initial metadata size exceeds limit")); + const char* expected_error = "received initial metadata size exceeds limit"; + grpc_slice actual_error = + grpc_slice_split_head(&details, strlen(expected_error)); + GPR_ASSERT(0 == grpc_slice_str_cmp(actual_error, expected_error)); GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); + grpc_slice_unref(actual_error); grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv);