diff --git a/src/core/lib/resource_quota/api.cc b/src/core/lib/resource_quota/api.cc index 3ba4ca6e21c..064668546eb 100644 --- a/src/core/lib/resource_quota/api.cc +++ b/src/core/lib/resource_quota/api.cc @@ -39,14 +39,19 @@ grpc_arg MakeArg(ResourceQuota* quota) { grpc_channel_args* EnsureResourceQuotaInChannelArgs( const grpc_channel_args* args) { - if (grpc_channel_args_find(args, GRPC_ARG_RESOURCE_QUOTA) != nullptr) { + const grpc_arg* existing = + grpc_channel_args_find(args, GRPC_ARG_RESOURCE_QUOTA); + if (existing != nullptr && existing->type == GRPC_ARG_POINTER && + existing->value.pointer.p == nullptr) { return grpc_channel_args_copy(args); } // If there's no existing quota, add it to the default one - shared between // all channel args declared thusly. This prevents us from accidentally not // sharing subchannels due to their channel args not specifying a quota. + const char* remove[] = {GRPC_ARG_RESOURCE_QUOTA}; auto new_arg = MakeArg(ResourceQuota::Default().get()); - return grpc_channel_args_copy_and_add(args, &new_arg, 1); + return grpc_channel_args_copy_and_add_and_remove(args, remove, 1, &new_arg, + 1); } grpc_channel_args* ChannelArgsWrappingResourceQuota(