Add GPR_UNLIKELY annotations mainly for the client path in error conditions

reviewable/pr15044/r1
Yash Tibrewal 7 years ago
parent 6a14efc023
commit 7f51ba8372
  1. 2
      src/core/ext/filters/client_channel/backup_poller.cc
  2. 2
      src/core/ext/filters/client_channel/channel_connectivity.cc
  3. 4
      src/core/ext/filters/client_channel/client_channel.cc
  4. 2
      src/core/ext/filters/client_channel/http_connect_handshaker.cc
  5. 6
      src/core/ext/filters/client_channel/http_proxy.cc
  6. 14
      src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc
  7. 11
      src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc
  8. 2
      src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc
  9. 32
      src/core/ext/filters/client_channel/parse_address.cc
  10. 5
      src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc
  11. 2
      src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc
  12. 2
      src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc
  13. 2
      src/core/ext/filters/client_channel/resolver_registry.cc
  14. 4
      src/core/ext/filters/client_channel/subchannel.cc
  15. 6
      src/core/ext/filters/http/client/http_client_filter.cc
  16. 8
      src/core/ext/filters/http/message_compress/message_compress_filter.cc
  17. 2
      src/core/ext/transport/chttp2/client/insecure/channel_create.cc
  18. 11
      src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc
  19. 2
      src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc
  20. 2
      src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc
  21. 17
      src/core/ext/transport/chttp2/transport/bin_decoder.cc
  22. 13
      src/core/ext/transport/chttp2/transport/chttp2_transport.cc
  23. 26
      src/core/ext/transport/chttp2/transport/parsing.cc
  24. 12
      src/core/ext/transport/chttp2/transport/writing.cc
  25. 6
      src/core/ext/transport/cronet/transport/cronet_transport.cc

@ -61,7 +61,7 @@ static void init_globals() {
char* env = gpr_getenv("GRPC_CLIENT_CHANNEL_BACKUP_POLL_INTERVAL_MS"); char* env = gpr_getenv("GRPC_CLIENT_CHANNEL_BACKUP_POLL_INTERVAL_MS");
if (env != nullptr) { if (env != nullptr) {
int poll_interval_ms = gpr_parse_nonnegative_int(env); int poll_interval_ms = gpr_parse_nonnegative_int(env);
if (poll_interval_ms == -1) { if (GPR_UNLIKELY(poll_interval_ms == -1)) {
gpr_log(GPR_ERROR, gpr_log(GPR_ERROR,
"Invalid GRPC_CLIENT_CHANNEL_BACKUP_POLL_INTERVAL_MS: %s, " "Invalid GRPC_CLIENT_CHANNEL_BACKUP_POLL_INTERVAL_MS: %s, "
"default value %d will be used.", "default value %d will be used.",

@ -40,7 +40,7 @@ grpc_connectivity_state grpc_channel_check_connectivity_state(
GRPC_API_TRACE( GRPC_API_TRACE(
"grpc_channel_check_connectivity_state(channel=%p, try_to_connect=%d)", 2, "grpc_channel_check_connectivity_state(channel=%p, try_to_connect=%d)", 2,
(channel, try_to_connect)); (channel, try_to_connect));
if (client_channel_elem->filter == &grpc_client_channel_filter) { if (GPR_LIKELY(client_channel_elem->filter == &grpc_client_channel_filter)) {
state = grpc_client_channel_check_connectivity_state(client_channel_elem, state = grpc_client_channel_check_connectivity_state(client_channel_elem,
try_to_connect); try_to_connect);

@ -379,7 +379,7 @@ static void on_resolver_result_changed_locked(void* arg, grpc_error* error) {
new_lb_policy = new_lb_policy =
grpc_core::LoadBalancingPolicyRegistry::CreateLoadBalancingPolicy( grpc_core::LoadBalancingPolicyRegistry::CreateLoadBalancingPolicy(
lb_policy_name, lb_policy_args); lb_policy_name, lb_policy_args);
if (new_lb_policy == nullptr) { if (GPR_UNLIKELY(new_lb_policy == nullptr)) {
gpr_log(GPR_ERROR, "could not create LB policy \"%s\"", gpr_log(GPR_ERROR, "could not create LB policy \"%s\"",
lb_policy_name); lb_policy_name);
} else { } else {
@ -2200,7 +2200,7 @@ static void add_retriable_send_initial_metadata_op(
&batch_data->send_initial_metadata_storage[calld->send_initial_metadata &batch_data->send_initial_metadata_storage[calld->send_initial_metadata
.list.count], .list.count],
retry_md); retry_md);
if (error != GRPC_ERROR_NONE) { if (GPR_UNLIKELY(error != GRPC_ERROR_NONE)) {
gpr_log(GPR_ERROR, "error adding retry metadata: %s", gpr_log(GPR_ERROR, "error adding retry metadata: %s",
grpc_error_string(error)); grpc_error_string(error));
GPR_ASSERT(false); GPR_ASSERT(false);

@ -280,7 +280,7 @@ static void http_connect_handshaker_do_handshake(
gpr_malloc(sizeof(grpc_http_header) * num_header_strings)); gpr_malloc(sizeof(grpc_http_header) * num_header_strings));
for (size_t i = 0; i < num_header_strings; ++i) { for (size_t i = 0; i < num_header_strings; ++i) {
char* sep = strchr(header_strings[i], ':'); char* sep = strchr(header_strings[i], ':');
if (sep == nullptr) { if (GPR_UNLIKELY(sep == nullptr)) {
gpr_log(GPR_ERROR, "skipping unparseable HTTP CONNECT header: %s", gpr_log(GPR_ERROR, "skipping unparseable HTTP CONNECT header: %s",
header_strings[i]); header_strings[i]);
continue; continue;

@ -50,11 +50,11 @@ static char* get_http_proxy_server(char** user_cred) {
size_t authority_nstrs; size_t authority_nstrs;
if (uri_str == nullptr) return nullptr; if (uri_str == nullptr) return nullptr;
grpc_uri* uri = grpc_uri_parse(uri_str, false /* suppress_errors */); grpc_uri* uri = grpc_uri_parse(uri_str, false /* suppress_errors */);
if (uri == nullptr || uri->authority == nullptr) { if (GPR_UNLIKELY(uri == nullptr || uri->authority == nullptr)) {
gpr_log(GPR_ERROR, "cannot parse value of 'http_proxy' env var"); gpr_log(GPR_ERROR, "cannot parse value of 'http_proxy' env var");
goto done; goto done;
} }
if (strcmp(uri->scheme, "http") != 0) { if (GPR_UNLIKELY(strcmp(uri->scheme, "http") != 0)) {
gpr_log(GPR_ERROR, "'%s' scheme not supported in proxy URI", uri->scheme); gpr_log(GPR_ERROR, "'%s' scheme not supported in proxy URI", uri->scheme);
goto done; goto done;
} }
@ -93,7 +93,7 @@ static bool proxy_mapper_map_name(grpc_proxy_mapper* mapper,
if (*name_to_resolve == nullptr) return false; if (*name_to_resolve == nullptr) return false;
char* no_proxy_str = nullptr; char* no_proxy_str = nullptr;
grpc_uri* uri = grpc_uri_parse(server_uri, false /* suppress_errors */); grpc_uri* uri = grpc_uri_parse(server_uri, false /* suppress_errors */);
if (uri == nullptr || uri->path[0] == '\0') { if (GPR_UNLIKELY(uri == nullptr || uri->path[0] == '\0')) {
gpr_log(GPR_ERROR, gpr_log(GPR_ERROR,
"'http_proxy' environment variable set, but cannot " "'http_proxy' environment variable set, but cannot "
"parse server URI '%s' -- not using proxy", "parse server URI '%s' -- not using proxy",

@ -398,7 +398,7 @@ grpc_lb_addresses* ExtractBackendAddresses(const grpc_lb_addresses* addresses) {
bool IsServerValid(const grpc_grpclb_server* server, size_t idx, bool log) { bool IsServerValid(const grpc_grpclb_server* server, size_t idx, bool log) {
if (server->drop) return false; if (server->drop) return false;
const grpc_grpclb_ip_address* ip = &server->ip_address; const grpc_grpclb_ip_address* ip = &server->ip_address;
if (server->port >> 16 != 0) { if (GPR_UNLIKELY(server->port >> 16 != 0)) {
if (log) { if (log) {
gpr_log(GPR_ERROR, gpr_log(GPR_ERROR,
"Invalid port '%d' at index %lu of serverlist. Ignoring.", "Invalid port '%d' at index %lu of serverlist. Ignoring.",
@ -406,7 +406,7 @@ bool IsServerValid(const grpc_grpclb_server* server, size_t idx, bool log) {
} }
return false; return false;
} }
if (ip->size != 4 && ip->size != 16) { if (GPR_UNLIKELY(ip->size != 4 && ip->size != 16)) {
if (log) { if (log) {
gpr_log(GPR_ERROR, gpr_log(GPR_ERROR,
"Expected IP to be 4 or 16 bytes, got %d at index %lu of " "Expected IP to be 4 or 16 bytes, got %d at index %lu of "
@ -714,7 +714,7 @@ void GrpcLb::BalancerCallState::SendClientLoadReportLocked() {
this, grpc_combiner_scheduler(grpclb_policy()->combiner())); this, grpc_combiner_scheduler(grpclb_policy()->combiner()));
grpc_call_error call_error = grpc_call_start_batch_and_execute( grpc_call_error call_error = grpc_call_start_batch_and_execute(
lb_call_, &op, 1, &client_load_report_closure_); lb_call_, &op, 1, &client_load_report_closure_);
if (call_error != GRPC_CALL_OK) { if (GPR_UNLIKELY(call_error != GRPC_CALL_OK)) {
gpr_log(GPR_ERROR, "[grpclb %p] call_error=%d", grpclb_policy_.get(), gpr_log(GPR_ERROR, "[grpclb %p] call_error=%d", grpclb_policy_.get(),
call_error); call_error);
GPR_ASSERT(GRPC_CALL_OK == call_error); GPR_ASSERT(GRPC_CALL_OK == call_error);
@ -936,7 +936,7 @@ grpc_lb_addresses* ExtractBalancerAddresses(
size_t lb_addresses_idx = 0; size_t lb_addresses_idx = 0;
for (size_t i = 0; i < addresses->num_addresses; ++i) { for (size_t i = 0; i < addresses->num_addresses; ++i) {
if (!addresses->addresses[i].is_balancer) continue; if (!addresses->addresses[i].is_balancer) continue;
if (addresses->addresses[i].user_data != nullptr) { if (GPR_UNLIKELY(addresses->addresses[i].user_data != nullptr)) {
gpr_log(GPR_ERROR, gpr_log(GPR_ERROR,
"This LB policy doesn't support user data. It will be ignored"); "This LB policy doesn't support user data. It will be ignored");
} }
@ -1284,7 +1284,7 @@ void GrpcLb::NotifyOnStateChangeLocked(grpc_connectivity_state* current,
void GrpcLb::ProcessChannelArgsLocked(const grpc_channel_args& args) { void GrpcLb::ProcessChannelArgsLocked(const grpc_channel_args& args) {
const grpc_arg* arg = grpc_channel_args_find(&args, GRPC_ARG_LB_ADDRESSES); const grpc_arg* arg = grpc_channel_args_find(&args, GRPC_ARG_LB_ADDRESSES);
if (arg == nullptr || arg->type != GRPC_ARG_POINTER) { if (GPR_UNLIKELY(arg == nullptr || arg->type != GRPC_ARG_POINTER)) {
// Ignore this update. // Ignore this update.
gpr_log( gpr_log(
GPR_ERROR, GPR_ERROR,
@ -1520,7 +1520,7 @@ void GrpcLb::PendingPickSetMetadataAndContext(PendingPick* pp) {
* policy (e.g., all addresses failed to connect). There won't be any * policy (e.g., all addresses failed to connect). There won't be any
* user_data/token available */ * user_data/token available */
if (pp->pick->connected_subchannel != nullptr) { if (pp->pick->connected_subchannel != nullptr) {
if (!GRPC_MDISNULL(pp->lb_token)) { if (GPR_LIKELY(!GRPC_MDISNULL(pp->lb_token))) {
AddLbTokenToInitialMetadata(GRPC_MDELEM_REF(pp->lb_token), AddLbTokenToInitialMetadata(GRPC_MDELEM_REF(pp->lb_token),
&pp->pick->lb_token_mdelem_storage, &pp->pick->lb_token_mdelem_storage,
pp->pick->initial_metadata); pp->pick->initial_metadata);
@ -1645,7 +1645,7 @@ void GrpcLb::CreateRoundRobinPolicyLocked(const Args& args) {
GPR_ASSERT(rr_policy_ == nullptr); GPR_ASSERT(rr_policy_ == nullptr);
rr_policy_ = LoadBalancingPolicyRegistry::CreateLoadBalancingPolicy( rr_policy_ = LoadBalancingPolicyRegistry::CreateLoadBalancingPolicy(
"round_robin", args); "round_robin", args);
if (rr_policy_ == nullptr) { if (GPR_UNLIKELY(rr_policy_ == nullptr)) {
gpr_log(GPR_ERROR, "[grpclb %p] Failure creating a RoundRobin policy", gpr_log(GPR_ERROR, "[grpclb %p] Failure creating a RoundRobin policy",
this); this);
return; return;

@ -29,7 +29,7 @@ static bool count_serverlist(pb_istream_t* stream, const pb_field_t* field,
void** arg) { void** arg) {
grpc_grpclb_serverlist* sl = static_cast<grpc_grpclb_serverlist*>(*arg); grpc_grpclb_serverlist* sl = static_cast<grpc_grpclb_serverlist*>(*arg);
grpc_grpclb_server server; grpc_grpclb_server server;
if (!pb_decode(stream, grpc_lb_v1_Server_fields, &server)) { if (GPR_UNLIKELY(!pb_decode(stream, grpc_lb_v1_Server_fields, &server))) {
gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(stream)); gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(stream));
return false; return false;
} }
@ -52,7 +52,7 @@ static bool decode_serverlist(pb_istream_t* stream, const pb_field_t* field,
GPR_ASSERT(dec_arg->serverlist->num_servers >= dec_arg->decoding_idx); GPR_ASSERT(dec_arg->serverlist->num_servers >= dec_arg->decoding_idx);
grpc_grpclb_server* server = grpc_grpclb_server* server =
static_cast<grpc_grpclb_server*>(gpr_zalloc(sizeof(grpc_grpclb_server))); static_cast<grpc_grpclb_server*>(gpr_zalloc(sizeof(grpc_grpclb_server)));
if (!pb_decode(stream, grpc_lb_v1_Server_fields, server)) { if (GPR_UNLIKELY(!pb_decode(stream, grpc_lb_v1_Server_fields, server))) {
gpr_free(server); gpr_free(server);
gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(stream)); gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(stream));
return false; return false;
@ -165,7 +165,8 @@ grpc_grpclb_initial_response* grpc_grpclb_initial_response_parse(
GRPC_SLICE_LENGTH(encoded_grpc_grpclb_response)); GRPC_SLICE_LENGTH(encoded_grpc_grpclb_response));
grpc_grpclb_response res; grpc_grpclb_response res;
memset(&res, 0, sizeof(grpc_grpclb_response)); memset(&res, 0, sizeof(grpc_grpclb_response));
if (!pb_decode(&stream, grpc_lb_v1_LoadBalanceResponse_fields, &res)) { if (GPR_UNLIKELY(
!pb_decode(&stream, grpc_lb_v1_LoadBalanceResponse_fields, &res))) {
gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&stream)); gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&stream));
return nullptr; return nullptr;
} }
@ -195,7 +196,7 @@ grpc_grpclb_serverlist* grpc_grpclb_response_parse_serverlist(
res.server_list.servers.funcs.decode = count_serverlist; res.server_list.servers.funcs.decode = count_serverlist;
res.server_list.servers.arg = sl; res.server_list.servers.arg = sl;
bool status = pb_decode(&stream, grpc_lb_v1_LoadBalanceResponse_fields, &res); bool status = pb_decode(&stream, grpc_lb_v1_LoadBalanceResponse_fields, &res);
if (!status) { if (GPR_UNLIKELY(!status)) {
gpr_free(sl); gpr_free(sl);
gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&stream)); gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&stream));
return nullptr; return nullptr;
@ -211,7 +212,7 @@ grpc_grpclb_serverlist* grpc_grpclb_response_parse_serverlist(
res.server_list.servers.arg = &decode_arg; res.server_list.servers.arg = &decode_arg;
status = pb_decode(&stream_at_start, grpc_lb_v1_LoadBalanceResponse_fields, status = pb_decode(&stream_at_start, grpc_lb_v1_LoadBalanceResponse_fields,
&res); &res);
if (!status) { if (GPR_UNLIKELY(!status)) {
grpc_grpclb_destroy_serverlist(sl); grpc_grpclb_destroy_serverlist(sl);
gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&stream)); gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&stream));
return nullptr; return nullptr;

@ -608,7 +608,7 @@ void RoundRobin::PingOneLocked(grpc_closure* on_initiate,
void RoundRobin::UpdateLocked(const grpc_channel_args& args) { void RoundRobin::UpdateLocked(const grpc_channel_args& args) {
const grpc_arg* arg = grpc_channel_args_find(&args, GRPC_ARG_LB_ADDRESSES); const grpc_arg* arg = grpc_channel_args_find(&args, GRPC_ARG_LB_ADDRESSES);
if (arg == nullptr || arg->type != GRPC_ARG_POINTER) { if (GPR_UNLIKELY(arg == nullptr || arg->type != GRPC_ARG_POINTER)) {
gpr_log(GPR_ERROR, "[RR %p] update provided no addresses; ignoring", this); gpr_log(GPR_ERROR, "[RR %p] update provided no addresses; ignoring", this);
// If we don't have a current subchannel list, go into TRANSIENT_FAILURE. // If we don't have a current subchannel list, go into TRANSIENT_FAILURE.
// Otherwise, keep using the current subchannel list (ignore this update). // Otherwise, keep using the current subchannel list (ignore this update).

@ -39,7 +39,7 @@
bool grpc_parse_unix(const grpc_uri* uri, bool grpc_parse_unix(const grpc_uri* uri,
grpc_resolved_address* resolved_addr) { grpc_resolved_address* resolved_addr) {
if (strcmp("unix", uri->scheme) != 0) { if (GPR_UNLIKELY(strcmp("unix", uri->scheme) != 0)) {
gpr_log(GPR_ERROR, "Expected 'unix' scheme, got '%s'", uri->scheme); gpr_log(GPR_ERROR, "Expected 'unix' scheme, got '%s'", uri->scheme);
return false; return false;
} }
@ -75,17 +75,18 @@ bool grpc_parse_ipv4_hostport(const char* hostport, grpc_resolved_address* addr,
addr->len = static_cast<socklen_t>(sizeof(grpc_sockaddr_in)); addr->len = static_cast<socklen_t>(sizeof(grpc_sockaddr_in));
grpc_sockaddr_in* in = reinterpret_cast<grpc_sockaddr_in*>(addr->addr); grpc_sockaddr_in* in = reinterpret_cast<grpc_sockaddr_in*>(addr->addr);
in->sin_family = GRPC_AF_INET; in->sin_family = GRPC_AF_INET;
if (grpc_inet_pton(GRPC_AF_INET, host, &in->sin_addr) == 0) { if (GPR_UNLIKELY(grpc_inet_pton(GRPC_AF_INET, host, &in->sin_addr) == 0)) {
if (log_errors) gpr_log(GPR_ERROR, "invalid ipv4 address: '%s'", host); if (log_errors) gpr_log(GPR_ERROR, "invalid ipv4 address: '%s'", host);
goto done; goto done;
} }
// Parse port. // Parse port.
if (port == nullptr) { if (GPR_UNLIKELY(port == nullptr)) {
if (log_errors) gpr_log(GPR_ERROR, "no port given for ipv4 scheme"); if (log_errors) gpr_log(GPR_ERROR, "no port given for ipv4 scheme");
goto done; goto done;
} }
int port_num; int port_num;
if (sscanf(port, "%d", &port_num) != 1 || port_num < 0 || port_num > 65535) { if (GPR_UNLIKELY(sscanf(port, "%d", &port_num) != 1 || port_num < 0 ||
port_num > 65535)) {
if (log_errors) gpr_log(GPR_ERROR, "invalid ipv4 port: '%s'", port); if (log_errors) gpr_log(GPR_ERROR, "invalid ipv4 port: '%s'", port);
goto done; goto done;
} }
@ -99,7 +100,7 @@ done:
bool grpc_parse_ipv4(const grpc_uri* uri, bool grpc_parse_ipv4(const grpc_uri* uri,
grpc_resolved_address* resolved_addr) { grpc_resolved_address* resolved_addr) {
if (strcmp("ipv4", uri->scheme) != 0) { if (GPR_UNLIKELY(strcmp("ipv4", uri->scheme) != 0)) {
gpr_log(GPR_ERROR, "Expected 'ipv4' scheme, got '%s'", uri->scheme); gpr_log(GPR_ERROR, "Expected 'ipv4' scheme, got '%s'", uri->scheme);
return false; return false;
} }
@ -130,32 +131,35 @@ bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr,
uint32_t sin6_scope_id = 0; uint32_t sin6_scope_id = 0;
strncpy(host_without_scope, host, host_without_scope_len); strncpy(host_without_scope, host, host_without_scope_len);
host_without_scope[host_without_scope_len] = '\0'; host_without_scope[host_without_scope_len] = '\0';
if (grpc_inet_pton(GRPC_AF_INET6, host_without_scope, &in6->sin6_addr) == if (GPR_UNLIKELY(grpc_inet_pton(GRPC_AF_INET6, host_without_scope,
0) { &in6->sin6_addr)) == 0) {
gpr_log(GPR_ERROR, "invalid ipv6 address: '%s'", host_without_scope); gpr_log(GPR_ERROR, "invalid ipv6 address: '%s'", host_without_scope);
goto done; goto done;
} }
if (gpr_parse_bytes_to_uint32(host_end + 1, if (GPR_UNLIKELY(
strlen(host) - host_without_scope_len - 1, gpr_parse_bytes_to_uint32(host_end + 1,
&sin6_scope_id) == 0) { strlen(host) - host_without_scope_len - 1,
&sin6_scope_id) == 0)) {
gpr_log(GPR_ERROR, "invalid ipv6 scope id: '%s'", host_end + 1); gpr_log(GPR_ERROR, "invalid ipv6 scope id: '%s'", host_end + 1);
goto done; goto done;
} }
// Handle "sin6_scope_id" being type "u_long". See grpc issue #10027. // Handle "sin6_scope_id" being type "u_long". See grpc issue #10027.
in6->sin6_scope_id = sin6_scope_id; in6->sin6_scope_id = sin6_scope_id;
} else { } else {
if (grpc_inet_pton(GRPC_AF_INET6, host, &in6->sin6_addr) == 0) { if (GPR_UNLIKELY(grpc_inet_pton(GRPC_AF_INET6, host, &in6->sin6_addr) ==
0)) {
gpr_log(GPR_ERROR, "invalid ipv6 address: '%s'", host); gpr_log(GPR_ERROR, "invalid ipv6 address: '%s'", host);
goto done; goto done;
} }
} }
// Parse port. // Parse port.
if (port == nullptr) { if (GPR_UNLIKELY(port == nullptr)) {
if (log_errors) gpr_log(GPR_ERROR, "no port given for ipv6 scheme"); if (log_errors) gpr_log(GPR_ERROR, "no port given for ipv6 scheme");
goto done; goto done;
} }
int port_num; int port_num;
if (sscanf(port, "%d", &port_num) != 1 || port_num < 0 || port_num > 65535) { if (GPR_UNLIKELY(sscanf(port, "%d", &port_num) != 1 || port_num < 0 ||
port_num > 65535)) {
if (log_errors) gpr_log(GPR_ERROR, "invalid ipv6 port: '%s'", port); if (log_errors) gpr_log(GPR_ERROR, "invalid ipv6 port: '%s'", port);
goto done; goto done;
} }
@ -169,7 +173,7 @@ done:
bool grpc_parse_ipv6(const grpc_uri* uri, bool grpc_parse_ipv6(const grpc_uri* uri,
grpc_resolved_address* resolved_addr) { grpc_resolved_address* resolved_addr) {
if (strcmp("ipv6", uri->scheme) != 0) { if (GPR_UNLIKELY(strcmp("ipv6", uri->scheme) != 0)) {
gpr_log(GPR_ERROR, "Expected 'ipv6' scheme, got '%s'", uri->scheme); gpr_log(GPR_ERROR, "Expected 'ipv6' scheme, got '%s'", uri->scheme);
return false; return false;
} }

@ -225,14 +225,15 @@ bool ValueInJsonArray(grpc_json* array, const char* value) {
char* ChooseServiceConfig(char* service_config_choice_json) { char* ChooseServiceConfig(char* service_config_choice_json) {
grpc_json* choices_json = grpc_json_parse_string(service_config_choice_json); grpc_json* choices_json = grpc_json_parse_string(service_config_choice_json);
if (choices_json == nullptr || choices_json->type != GRPC_JSON_ARRAY) { if (GPR_UNLIKELY(choices_json == nullptr ||
choices_json->type != GRPC_JSON_ARRAY)) {
gpr_log(GPR_ERROR, "cannot parse service config JSON string"); gpr_log(GPR_ERROR, "cannot parse service config JSON string");
return nullptr; return nullptr;
} }
char* service_config = nullptr; char* service_config = nullptr;
for (grpc_json* choice = choices_json->child; choice != nullptr; for (grpc_json* choice = choices_json->child; choice != nullptr;
choice = choice->next) { choice = choice->next) {
if (choice->type != GRPC_JSON_OBJECT) { if (GPR_UNLIKELY(choice->type != GRPC_JSON_OBJECT)) {
gpr_log(GPR_ERROR, "cannot parse service config JSON string"); gpr_log(GPR_ERROR, "cannot parse service config JSON string");
break; break;
} }

@ -310,7 +310,7 @@ class NativeDnsResolverFactory : public ResolverFactory {
public: public:
OrphanablePtr<Resolver> CreateResolver( OrphanablePtr<Resolver> CreateResolver(
const ResolverArgs& args) const override { const ResolverArgs& args) const override {
if (0 != strcmp(args.uri->authority, "")) { if (GPR_UNLIKELY(0 != strcmp(args.uri->authority, ""))) {
gpr_log(GPR_ERROR, "authority based dns uri's not supported"); gpr_log(GPR_ERROR, "authority based dns uri's not supported");
return OrphanablePtr<Resolver>(nullptr); return OrphanablePtr<Resolver>(nullptr);
} }

@ -123,7 +123,7 @@ void DoNothing(void* ignored) {}
OrphanablePtr<Resolver> CreateSockaddrResolver( OrphanablePtr<Resolver> CreateSockaddrResolver(
const ResolverArgs& args, const ResolverArgs& args,
bool parse(const grpc_uri* uri, grpc_resolved_address* dst)) { bool parse(const grpc_uri* uri, grpc_resolved_address* dst)) {
if (0 != strcmp(args.uri->authority, "")) { if (GPR_UNLIKELY(0 != strcmp(args.uri->authority, ""))) {
gpr_log(GPR_ERROR, "authority-based URIs not supported by the %s scheme", gpr_log(GPR_ERROR, "authority-based URIs not supported by the %s scheme",
args.uri->scheme); args.uri->scheme);
return OrphanablePtr<Resolver>(nullptr); return OrphanablePtr<Resolver>(nullptr);

@ -74,7 +74,7 @@ class RegistryState {
*uri = grpc_uri_parse(*canonical_target, 1); *uri = grpc_uri_parse(*canonical_target, 1);
factory = factory =
*uri == nullptr ? nullptr : LookupResolverFactory((*uri)->scheme); *uri == nullptr ? nullptr : LookupResolverFactory((*uri)->scheme);
if (factory == nullptr) { if (GPR_UNLIKELY(factory == nullptr)) {
grpc_uri_destroy(grpc_uri_parse(target, 0)); grpc_uri_destroy(grpc_uri_parse(target, 0));
grpc_uri_destroy(grpc_uri_parse(*canonical_target, 0)); grpc_uri_destroy(grpc_uri_parse(*canonical_target, 0));
gpr_log(GPR_ERROR, "don't know how to resolve '%s' or '%s'", target, gpr_log(GPR_ERROR, "don't know how to resolve '%s' or '%s'", target,

@ -577,7 +577,7 @@ static bool publish_transport_locked(grpc_subchannel* c) {
grpc_error* error = grpc_channel_stack_builder_finish( grpc_error* error = grpc_channel_stack_builder_finish(
builder, 0, 1, connection_destroy, nullptr, builder, 0, 1, connection_destroy, nullptr,
reinterpret_cast<void**>(&stk)); reinterpret_cast<void**>(&stk));
if (error != GRPC_ERROR_NONE) { if (GPR_UNLIKELY(error != GRPC_ERROR_NONE)) {
grpc_transport_destroy(c->connecting_result.transport); grpc_transport_destroy(c->connecting_result.transport);
gpr_log(GPR_ERROR, "error initializing subchannel stack: %s", gpr_log(GPR_ERROR, "error initializing subchannel stack: %s",
grpc_error_string(error)); grpc_error_string(error));
@ -803,7 +803,7 @@ grpc_error* ConnectedSubchannel::CreateCall(const CallArgs& args,
}; };
grpc_error* error = grpc_call_stack_init( grpc_error* error = grpc_call_stack_init(
channel_stack_, 1, subchannel_call_destroy, *call, &call_args); channel_stack_, 1, subchannel_call_destroy, *call, &call_args);
if (error != GRPC_ERROR_NONE) { if (GPR_UNLIKELY(error != GRPC_ERROR_NONE)) {
const char* error_string = grpc_error_string(error); const char* error_string = grpc_error_string(error);
gpr_log(GPR_ERROR, "error: %s", error_string); gpr_log(GPR_ERROR, "error: %s", error_string);
return error; return error;

@ -460,7 +460,7 @@ static size_t max_payload_size_from_args(const grpc_channel_args* args) {
if (args != nullptr) { if (args != nullptr) {
for (size_t i = 0; i < args->num_args; ++i) { for (size_t i = 0; i < args->num_args; ++i) {
if (0 == strcmp(args->args[i].key, GRPC_ARG_MAX_PAYLOAD_SIZE_FOR_GET)) { if (0 == strcmp(args->args[i].key, GRPC_ARG_MAX_PAYLOAD_SIZE_FOR_GET)) {
if (args->args[i].type != GRPC_ARG_INTEGER) { if (GPR_UNLIKELY(args->args[i].type != GRPC_ARG_INTEGER)) {
gpr_log(GPR_ERROR, "%s: must be an integer", gpr_log(GPR_ERROR, "%s: must be an integer",
GRPC_ARG_MAX_PAYLOAD_SIZE_FOR_GET); GRPC_ARG_MAX_PAYLOAD_SIZE_FOR_GET);
} else { } else {
@ -484,7 +484,7 @@ static grpc_slice user_agent_from_args(const grpc_channel_args* args,
for (i = 0; args && i < args->num_args; i++) { for (i = 0; args && i < args->num_args; i++) {
if (0 == strcmp(args->args[i].key, GRPC_ARG_PRIMARY_USER_AGENT_STRING)) { if (0 == strcmp(args->args[i].key, GRPC_ARG_PRIMARY_USER_AGENT_STRING)) {
if (args->args[i].type != GRPC_ARG_STRING) { if (GPR_UNLIKELY(args->args[i].type != GRPC_ARG_STRING)) {
gpr_log(GPR_ERROR, "Channel argument '%s' should be a string", gpr_log(GPR_ERROR, "Channel argument '%s' should be a string",
GRPC_ARG_PRIMARY_USER_AGENT_STRING); GRPC_ARG_PRIMARY_USER_AGENT_STRING);
} else { } else {
@ -503,7 +503,7 @@ static grpc_slice user_agent_from_args(const grpc_channel_args* args,
for (i = 0; args && i < args->num_args; i++) { for (i = 0; args && i < args->num_args; i++) {
if (0 == strcmp(args->args[i].key, GRPC_ARG_SECONDARY_USER_AGENT_STRING)) { if (0 == strcmp(args->args[i].key, GRPC_ARG_SECONDARY_USER_AGENT_STRING)) {
if (args->args[i].type != GRPC_ARG_STRING) { if (GPR_UNLIKELY(args->args[i].type != GRPC_ARG_STRING)) {
gpr_log(GPR_ERROR, "Channel argument '%s' should be a string", gpr_log(GPR_ERROR, "Channel argument '%s' should be a string",
GRPC_ARG_SECONDARY_USER_AGENT_STRING); GRPC_ARG_SECONDARY_USER_AGENT_STRING);
} else { } else {

@ -116,8 +116,8 @@ static grpc_error* process_send_initial_metadata(
if (initial_metadata->idx.named.grpc_internal_encoding_request != nullptr) { if (initial_metadata->idx.named.grpc_internal_encoding_request != nullptr) {
grpc_mdelem md = grpc_mdelem md =
initial_metadata->idx.named.grpc_internal_encoding_request->md; initial_metadata->idx.named.grpc_internal_encoding_request->md;
if (!grpc_compression_algorithm_parse(GRPC_MDVALUE(md), if (GPR_UNLIKELY(!grpc_compression_algorithm_parse(
&compression_algorithm)) { GRPC_MDVALUE(md), &compression_algorithm))) {
char* val = grpc_slice_to_c_string(GRPC_MDVALUE(md)); char* val = grpc_slice_to_c_string(GRPC_MDVALUE(md));
gpr_log(GPR_ERROR, gpr_log(GPR_ERROR,
"Invalid compression algorithm: '%s' (unknown). Ignoring.", val); "Invalid compression algorithm: '%s' (unknown). Ignoring.", val);
@ -125,8 +125,8 @@ static grpc_error* process_send_initial_metadata(
calld->message_compression_algorithm = GRPC_MESSAGE_COMPRESS_NONE; calld->message_compression_algorithm = GRPC_MESSAGE_COMPRESS_NONE;
stream_compression_algorithm = GRPC_STREAM_COMPRESS_NONE; stream_compression_algorithm = GRPC_STREAM_COMPRESS_NONE;
} }
if (!GPR_BITGET(channeld->enabled_algorithms_bitset, if (GPR_UNLIKELY(!GPR_BITGET(channeld->enabled_algorithms_bitset,
compression_algorithm)) { compression_algorithm))) {
char* val = grpc_slice_to_c_string(GRPC_MDVALUE(md)); char* val = grpc_slice_to_c_string(GRPC_MDVALUE(md));
gpr_log(GPR_ERROR, gpr_log(GPR_ERROR,
"Invalid compression algorithm: '%s' (previously disabled). " "Invalid compression algorithm: '%s' (previously disabled). "

@ -54,7 +54,7 @@ static grpc_subchannel* client_channel_factory_create_subchannel(
static grpc_channel* client_channel_factory_create_channel( static grpc_channel* client_channel_factory_create_channel(
grpc_client_channel_factory* cc_factory, const char* target, grpc_client_channel_factory* cc_factory, const char* target,
grpc_client_channel_type type, const grpc_channel_args* args) { grpc_client_channel_type type, const grpc_channel_args* args) {
if (target == nullptr) { if (GPR_UNLIKELY(target == nullptr)) {
gpr_log(GPR_ERROR, "cannot create channel with NULL target name"); gpr_log(GPR_ERROR, "cannot create channel with NULL target name");
return nullptr; return nullptr;
} }

@ -50,14 +50,15 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args(
const grpc_subchannel_args* args) { const grpc_subchannel_args* args) {
grpc_channel_credentials* channel_credentials = grpc_channel_credentials* channel_credentials =
grpc_channel_credentials_find_in_args(args->args); grpc_channel_credentials_find_in_args(args->args);
if (channel_credentials == nullptr) { if (GPR_UNLIKELY(channel_credentials == nullptr)) {
gpr_log(GPR_ERROR, gpr_log(GPR_ERROR,
"Can't create subchannel: channel credentials missing for secure " "Can't create subchannel: channel credentials missing for secure "
"channel."); "channel.");
return nullptr; return nullptr;
} }
// Make sure security connector does not already exist in args. // Make sure security connector does not already exist in args.
if (grpc_security_connector_find_in_args(args->args) != nullptr) { if (GPR_UNLIKELY(grpc_security_connector_find_in_args(args->args) !=
nullptr)) {
gpr_log(GPR_ERROR, gpr_log(GPR_ERROR,
"Can't create subchannel: security connector already present in " "Can't create subchannel: security connector already present in "
"channel args."); "channel args.");
@ -117,7 +118,7 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args(
grpc_channel_credentials_create_security_connector( grpc_channel_credentials_create_security_connector(
channel_credentials, authority.get(), args_with_authority, channel_credentials, authority.get(), args_with_authority,
&subchannel_security_connector, &new_args_from_connector); &subchannel_security_connector, &new_args_from_connector);
if (security_status != GRPC_SECURITY_OK) { if (GPR_UNLIKELY(security_status != GRPC_SECURITY_OK)) {
gpr_log(GPR_ERROR, gpr_log(GPR_ERROR,
"Failed to create secure subchannel for secure name '%s'", "Failed to create secure subchannel for secure name '%s'",
authority.get()); authority.get());
@ -149,7 +150,7 @@ static grpc_subchannel* client_channel_factory_create_subchannel(
grpc_client_channel_factory* cc_factory, const grpc_subchannel_args* args) { grpc_client_channel_factory* cc_factory, const grpc_subchannel_args* args) {
grpc_subchannel_args* subchannel_args = grpc_subchannel_args* subchannel_args =
get_secure_naming_subchannel_args(args); get_secure_naming_subchannel_args(args);
if (subchannel_args == nullptr) { if (GPR_UNLIKELY(subchannel_args == nullptr)) {
gpr_log( gpr_log(
GPR_ERROR, GPR_ERROR,
"Failed to create subchannel arguments during subchannel creation."); "Failed to create subchannel arguments during subchannel creation.");
@ -167,7 +168,7 @@ static grpc_subchannel* client_channel_factory_create_subchannel(
static grpc_channel* client_channel_factory_create_channel( static grpc_channel* client_channel_factory_create_channel(
grpc_client_channel_factory* cc_factory, const char* target, grpc_client_channel_factory* cc_factory, const char* target,
grpc_client_channel_type type, const grpc_channel_args* args) { grpc_client_channel_type type, const grpc_channel_args* args) {
if (target == nullptr) { if (GPR_UNLIKELY(target == nullptr)) {
gpr_log(GPR_ERROR, "cannot create channel with NULL target name"); gpr_log(GPR_ERROR, "cannot create channel with NULL target name");
return nullptr; return nullptr;
} }

@ -35,7 +35,7 @@ int grpc_server_add_insecure_http2_port(grpc_server* server, const char* addr) {
grpc_error* err = grpc_chttp2_server_add_port( grpc_error* err = grpc_chttp2_server_add_port(
server, addr, server, addr,
grpc_channel_args_copy(grpc_server_get_channel_args(server)), &port_num); grpc_channel_args_copy(grpc_server_get_channel_args(server)), &port_num);
if (err != GRPC_ERROR_NONE) { if (GPR_UNLIKELY(err != GRPC_ERROR_NONE)) {
const char* msg = grpc_error_string(err); const char* msg = grpc_error_string(err);
gpr_log(GPR_ERROR, "%s", msg); gpr_log(GPR_ERROR, "%s", msg);

@ -79,7 +79,7 @@ done:
GRPC_SECURITY_CONNECTOR_UNREF(&sc->base, "server"); GRPC_SECURITY_CONNECTOR_UNREF(&sc->base, "server");
} }
if (err != GRPC_ERROR_NONE) { if (GPR_UNLIKELY(err != GRPC_ERROR_NONE)) {
const char* msg = grpc_error_string(err); const char* msg = grpc_error_string(err);
gpr_log(GPR_ERROR, "%s", msg); gpr_log(GPR_ERROR, "%s", msg);

@ -55,7 +55,7 @@ static bool input_is_valid(uint8_t* input_ptr, size_t length) {
size_t i; size_t i;
for (i = 0; i < length; ++i) { for (i = 0; i < length; ++i) {
if ((decode_table[input_ptr[i]] & 0xC0) != 0) { if (GPR_UNLIKELY((decode_table[input_ptr[i]] & 0xC0) != 0)) {
gpr_log(GPR_ERROR, gpr_log(GPR_ERROR,
"Base64 decoding failed, invalid character '%c' in base64 " "Base64 decoding failed, invalid character '%c' in base64 "
"input.\n", "input.\n",
@ -86,14 +86,14 @@ size_t grpc_chttp2_base64_infer_length_after_decode(const grpc_slice& slice) {
while (len > 0 && bytes[len - 1] == '=') { while (len > 0 && bytes[len - 1] == '=') {
len--; len--;
} }
if (GRPC_SLICE_LENGTH(slice) - len > 2) { if (GPR_UNLIKELY(GRPC_SLICE_LENGTH(slice) - len > 2)) {
gpr_log(GPR_ERROR, gpr_log(GPR_ERROR,
"Base64 decoding failed. Input has more than 2 paddings."); "Base64 decoding failed. Input has more than 2 paddings.");
return 0; return 0;
} }
size_t tuples = len / 4; size_t tuples = len / 4;
size_t tail_case = len % 4; size_t tail_case = len % 4;
if (tail_case == 1) { if (GPR_UNLIKELY(tail_case == 1)) {
gpr_log(GPR_ERROR, gpr_log(GPR_ERROR,
"Base64 decoding failed. Input has a length of %zu (without" "Base64 decoding failed. Input has a length of %zu (without"
" padding), which is invalid.\n", " padding), which is invalid.\n",
@ -164,7 +164,7 @@ grpc_slice grpc_chttp2_base64_decode(grpc_slice input) {
struct grpc_base64_decode_context ctx; struct grpc_base64_decode_context ctx;
grpc_slice output; grpc_slice output;
if (input_length % 4 != 0) { if (GPR_UNLIKELY(input_length % 4 != 0)) {
gpr_log(GPR_ERROR, gpr_log(GPR_ERROR,
"Base64 decoding failed, input of " "Base64 decoding failed, input of "
"grpc_chttp2_base64_decode has a length of %d, which is not a " "grpc_chttp2_base64_decode has a length of %d, which is not a "
@ -190,7 +190,7 @@ grpc_slice grpc_chttp2_base64_decode(grpc_slice input) {
ctx.output_end = GRPC_SLICE_END_PTR(output); ctx.output_end = GRPC_SLICE_END_PTR(output);
ctx.contains_tail = false; ctx.contains_tail = false;
if (!grpc_base64_decode_partial(&ctx)) { if (GPR_UNLIKELY(!grpc_base64_decode_partial(&ctx))) {
char* s = grpc_slice_to_c_string(input); char* s = grpc_slice_to_c_string(input);
gpr_log(GPR_ERROR, "Base64 decoding failed, input string:\n%s\n", s); gpr_log(GPR_ERROR, "Base64 decoding failed, input string:\n%s\n", s);
gpr_free(s); gpr_free(s);
@ -209,7 +209,7 @@ grpc_slice grpc_chttp2_base64_decode_with_length(grpc_slice input,
struct grpc_base64_decode_context ctx; struct grpc_base64_decode_context ctx;
// The length of a base64 string cannot be 4 * n + 1 // The length of a base64 string cannot be 4 * n + 1
if (input_length % 4 == 1) { if (GPR_UNLIKELY(input_length % 4 == 1)) {
gpr_log(GPR_ERROR, gpr_log(GPR_ERROR,
"Base64 decoding failed, input of " "Base64 decoding failed, input of "
"grpc_chttp2_base64_decode_with_length has a length of %d, which " "grpc_chttp2_base64_decode_with_length has a length of %d, which "
@ -219,7 +219,8 @@ grpc_slice grpc_chttp2_base64_decode_with_length(grpc_slice input,
return grpc_empty_slice(); return grpc_empty_slice();
} }
if (output_length > input_length / 4 * 3 + tail_xtra[input_length % 4]) { if (GPR_UNLIKELY(output_length >
input_length / 4 * 3 + tail_xtra[input_length % 4])) {
gpr_log( gpr_log(
GPR_ERROR, GPR_ERROR,
"Base64 decoding failed, output_length %d is longer " "Base64 decoding failed, output_length %d is longer "
@ -236,7 +237,7 @@ grpc_slice grpc_chttp2_base64_decode_with_length(grpc_slice input,
ctx.output_end = GRPC_SLICE_END_PTR(output); ctx.output_end = GRPC_SLICE_END_PTR(output);
ctx.contains_tail = true; ctx.contains_tail = true;
if (!grpc_base64_decode_partial(&ctx)) { if (GPR_UNLIKELY(!grpc_base64_decode_partial(&ctx))) {
char* s = grpc_slice_to_c_string(input); char* s = grpc_slice_to_c_string(input);
gpr_log(GPR_ERROR, "Base64 decoding failed, input string:\n%s\n", s); gpr_log(GPR_ERROR, "Base64 decoding failed, input string:\n%s\n", s);
gpr_free(s); gpr_free(s);

@ -368,7 +368,7 @@ static void init_transport(grpc_chttp2_transport* t,
const int value = const int value =
grpc_channel_arg_get_integer(&channel_args->args[i], options); grpc_channel_arg_get_integer(&channel_args->args[i], options);
if (value >= 0) { if (value >= 0) {
if ((t->next_stream_id & 1) != (value & 1)) { if (GPR_UNLIKELY((t->next_stream_id & 1) != (value & 1))) {
gpr_log(GPR_ERROR, "%s: low bit must be %d on %s", gpr_log(GPR_ERROR, "%s: low bit must be %d on %s",
GRPC_ARG_HTTP2_INITIAL_SEQUENCE_NUMBER, GRPC_ARG_HTTP2_INITIAL_SEQUENCE_NUMBER,
t->next_stream_id & 1, is_client ? "client" : "server"); t->next_stream_id & 1, is_client ? "client" : "server");
@ -447,7 +447,7 @@ static void init_transport(grpc_chttp2_transport* t,
grpc_channel_arg_get_integer(&channel_args->args[i], {0, 0, 1})); grpc_channel_arg_get_integer(&channel_args->args[i], {0, 0, 1}));
} else if (0 == strcmp(channel_args->args[i].key, } else if (0 == strcmp(channel_args->args[i].key,
GRPC_ARG_OPTIMIZATION_TARGET)) { GRPC_ARG_OPTIMIZATION_TARGET)) {
if (channel_args->args[i].type != GRPC_ARG_STRING) { if (GPR_UNLIKELY(channel_args->args[i].type != GRPC_ARG_STRING)) {
gpr_log(GPR_ERROR, "%s should be a string", gpr_log(GPR_ERROR, "%s should be a string",
GRPC_ARG_OPTIMIZATION_TARGET); GRPC_ARG_OPTIMIZATION_TARGET);
} else if (0 == strcmp(channel_args->args[i].value.string, "blend")) { } else if (0 == strcmp(channel_args->args[i].value.string, "blend")) {
@ -718,7 +718,7 @@ static void destroy_stream_locked(void* sp, grpc_error* error) {
grpc_chttp2_list_remove_stalled_by_stream(t, s); grpc_chttp2_list_remove_stalled_by_stream(t, s);
for (int i = 0; i < STREAM_LIST_COUNT; i++) { for (int i = 0; i < STREAM_LIST_COUNT; i++) {
if (s->included[i]) { if (GPR_UNLIKELY(s->included[i])) {
gpr_log(GPR_ERROR, "%s stream %d still included in list %d", gpr_log(GPR_ERROR, "%s stream %d still included in list %d",
t->is_client ? "client" : "server", s->id, i); t->is_client ? "client" : "server", s->id, i);
abort(); abort();
@ -1088,8 +1088,9 @@ void grpc_chttp2_add_incoming_goaway(grpc_chttp2_transport* t,
* data equal to "too_many_pings", it should log the occurrence at a log level * data equal to "too_many_pings", it should log the occurrence at a log level
* that is enabled by default and double the configured KEEPALIVE_TIME used * that is enabled by default and double the configured KEEPALIVE_TIME used
* for new connections on that channel. */ * for new connections on that channel. */
if (t->is_client && goaway_error == GRPC_HTTP2_ENHANCE_YOUR_CALM && if (GPR_UNLIKELY(t->is_client &&
grpc_slice_str_cmp(goaway_text, "too_many_pings") == 0) { goaway_error == GRPC_HTTP2_ENHANCE_YOUR_CALM &&
grpc_slice_str_cmp(goaway_text, "too_many_pings") == 0)) {
gpr_log(GPR_ERROR, gpr_log(GPR_ERROR,
"Received a GOAWAY with error code ENHANCE_YOUR_CALM and debug " "Received a GOAWAY with error code ENHANCE_YOUR_CALM and debug "
"data equal to \"too_many_pings\""); "data equal to \"too_many_pings\"");
@ -2701,7 +2702,7 @@ static void keepalive_watchdog_fired_locked(void* arg, grpc_error* error) {
} else { } else {
/* The watchdog timer should have been cancelled by /* The watchdog timer should have been cancelled by
* finish_keepalive_ping_locked. */ * finish_keepalive_ping_locked. */
if (error != GRPC_ERROR_CANCELLED) { if (GPR_UNLIKELY(error != GRPC_ERROR_CANCELLED)) {
gpr_log(GPR_ERROR, "keepalive_ping_end state error: %d (expect: %d)", gpr_log(GPR_ERROR, "keepalive_ping_end state error: %d (expect: %d)",
t->keepalive_state, GRPC_CHTTP2_KEEPALIVE_STATE_PINGING); t->keepalive_state, GRPC_CHTTP2_KEEPALIVE_STATE_PINGING);
} }

@ -422,7 +422,8 @@ static void on_initial_header(void* tp, grpc_mdelem md) {
if (cached_timeout != nullptr) { if (cached_timeout != nullptr) {
timeout = *cached_timeout; timeout = *cached_timeout;
} else { } else {
if (!grpc_http2_decode_timeout(GRPC_MDVALUE(md), &timeout)) { if (GPR_UNLIKELY(
!grpc_http2_decode_timeout(GRPC_MDVALUE(md), &timeout))) {
char* val = grpc_slice_to_c_string(GRPC_MDVALUE(md)); char* val = grpc_slice_to_c_string(GRPC_MDVALUE(md));
gpr_log(GPR_ERROR, "Ignoring bad timeout value '%s'", val); gpr_log(GPR_ERROR, "Ignoring bad timeout value '%s'", val);
gpr_free(val); gpr_free(val);
@ -550,15 +551,15 @@ static grpc_error* init_header_frame_parser(grpc_chttp2_transport* t,
/* could be a new grpc_chttp2_stream or an existing grpc_chttp2_stream */ /* could be a new grpc_chttp2_stream or an existing grpc_chttp2_stream */
s = grpc_chttp2_parsing_lookup_stream(t, t->incoming_stream_id); s = grpc_chttp2_parsing_lookup_stream(t, t->incoming_stream_id);
if (s == nullptr) { if (s == nullptr) {
if (is_continuation) { if (GPR_UNLIKELY(is_continuation)) {
GRPC_CHTTP2_IF_TRACING( GRPC_CHTTP2_IF_TRACING(
gpr_log(GPR_ERROR, gpr_log(GPR_ERROR,
"grpc_chttp2_stream disbanded before CONTINUATION received")); "grpc_chttp2_stream disbanded before CONTINUATION received"));
return init_skip_frame_parser(t, 1); return init_skip_frame_parser(t, 1);
} }
if (t->is_client) { if (t->is_client) {
if ((t->incoming_stream_id & 1) && if (GPR_LIKELY((t->incoming_stream_id & 1) &&
t->incoming_stream_id < t->next_stream_id) { t->incoming_stream_id < t->next_stream_id)) {
/* this is an old (probably cancelled) grpc_chttp2_stream */ /* this is an old (probably cancelled) grpc_chttp2_stream */
} else { } else {
GRPC_CHTTP2_IF_TRACING(gpr_log( GRPC_CHTTP2_IF_TRACING(gpr_log(
@ -569,7 +570,7 @@ static grpc_error* init_header_frame_parser(grpc_chttp2_transport* t,
grpc_chttp2_hpack_parser_set_has_priority(&t->hpack_parser); grpc_chttp2_hpack_parser_set_has_priority(&t->hpack_parser);
} }
return err; return err;
} else if (t->last_new_stream_id >= t->incoming_stream_id) { } else if (GPR_UNLIKELY(t->last_new_stream_id >= t->incoming_stream_id)) {
GRPC_CHTTP2_IF_TRACING(gpr_log( GRPC_CHTTP2_IF_TRACING(gpr_log(
GPR_ERROR, GPR_ERROR,
"ignoring out of order new grpc_chttp2_stream request on server; " "ignoring out of order new grpc_chttp2_stream request on server; "
@ -577,21 +578,22 @@ static grpc_error* init_header_frame_parser(grpc_chttp2_transport* t,
"id=%d, new grpc_chttp2_stream id=%d", "id=%d, new grpc_chttp2_stream id=%d",
t->last_new_stream_id, t->incoming_stream_id)); t->last_new_stream_id, t->incoming_stream_id));
return init_skip_frame_parser(t, 1); return init_skip_frame_parser(t, 1);
} else if ((t->incoming_stream_id & 1) == 0) { } else if (GPR_UNLIKELY((t->incoming_stream_id & 1) == 0)) {
GRPC_CHTTP2_IF_TRACING(gpr_log( GRPC_CHTTP2_IF_TRACING(gpr_log(
GPR_ERROR, GPR_ERROR,
"ignoring grpc_chttp2_stream with non-client generated index %d", "ignoring grpc_chttp2_stream with non-client generated index %d",
t->incoming_stream_id)); t->incoming_stream_id));
return init_skip_frame_parser(t, 1); return init_skip_frame_parser(t, 1);
} else if (grpc_chttp2_stream_map_size(&t->stream_map) >= } else if (GPR_UNLIKELY(
t->settings[GRPC_ACKED_SETTINGS] grpc_chttp2_stream_map_size(&t->stream_map) >=
[GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS]) { t->settings[GRPC_ACKED_SETTINGS]
[GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS])) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Max stream count exceeded"); return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Max stream count exceeded");
} }
t->last_new_stream_id = t->incoming_stream_id; t->last_new_stream_id = t->incoming_stream_id;
s = t->incoming_stream = s = t->incoming_stream =
grpc_chttp2_parsing_accept_stream(t, t->incoming_stream_id); grpc_chttp2_parsing_accept_stream(t, t->incoming_stream_id);
if (s == nullptr) { if (GPR_UNLIKELY(s == nullptr)) {
GRPC_CHTTP2_IF_TRACING( GRPC_CHTTP2_IF_TRACING(
gpr_log(GPR_ERROR, "grpc_chttp2_stream not accepted")); gpr_log(GPR_ERROR, "grpc_chttp2_stream not accepted"));
return init_skip_frame_parser(t, 1); return init_skip_frame_parser(t, 1);
@ -601,7 +603,7 @@ static grpc_error* init_header_frame_parser(grpc_chttp2_transport* t,
} }
GPR_ASSERT(s != nullptr); GPR_ASSERT(s != nullptr);
s->stats.incoming.framing_bytes += 9; s->stats.incoming.framing_bytes += 9;
if (s->read_closed) { if (GPR_UNLIKELY(s->read_closed)) {
GRPC_CHTTP2_IF_TRACING(gpr_log( GRPC_CHTTP2_IF_TRACING(gpr_log(
GPR_ERROR, "skipping already closed grpc_chttp2_stream header")); GPR_ERROR, "skipping already closed grpc_chttp2_stream header"));
t->incoming_stream = nullptr; t->incoming_stream = nullptr;
@ -723,7 +725,7 @@ static grpc_error* parse_frame_slice(grpc_chttp2_transport* t, grpc_slice slice,
int is_last) { int is_last) {
grpc_chttp2_stream* s = t->incoming_stream; grpc_chttp2_stream* s = t->incoming_stream;
grpc_error* err = t->parser(t->parser_data, t, s, slice, is_last); grpc_error* err = t->parser(t->parser_data, t, s, slice, is_last);
if (err == GRPC_ERROR_NONE) { if (GPR_LIKELY(err == GRPC_ERROR_NONE)) {
return err; return err;
} else if (grpc_error_get_int(err, GRPC_ERROR_INT_STREAM_ID, nullptr)) { } else if (grpc_error_get_int(err, GRPC_ERROR_INT_STREAM_ID, nullptr)) {
if (grpc_http_trace.enabled()) { if (grpc_http_trace.enabled()) {

@ -337,10 +337,10 @@ class DataSendContext {
s_->fetching_send_message == nullptr); s_->fetching_send_message == nullptr);
if (is_last_data_frame && s_->send_trailing_metadata != nullptr && if (is_last_data_frame && s_->send_trailing_metadata != nullptr &&
s_->stream_compression_ctx != nullptr) { s_->stream_compression_ctx != nullptr) {
if (!grpc_stream_compress( if (GPR_UNLIKELY(!grpc_stream_compress(
s_->stream_compression_ctx, &s_->flow_controlled_buffer, s_->stream_compression_ctx, &s_->flow_controlled_buffer,
&s_->compressed_data_buffer, nullptr, MAX_SIZE_T, &s_->compressed_data_buffer, nullptr, MAX_SIZE_T,
GRPC_STREAM_COMPRESSION_FLUSH_FINISH)) { GRPC_STREAM_COMPRESSION_FLUSH_FINISH))) {
gpr_log(GPR_ERROR, "Stream compression failed."); gpr_log(GPR_ERROR, "Stream compression failed.");
} }
grpc_stream_compression_context_destroy(s_->stream_compression_ctx); grpc_stream_compression_context_destroy(s_->stream_compression_ctx);
@ -368,10 +368,10 @@ class DataSendContext {
grpc_stream_compression_context_create(s_->stream_compression_method); grpc_stream_compression_context_create(s_->stream_compression_method);
} }
s_->uncompressed_data_size = s_->flow_controlled_buffer.length; s_->uncompressed_data_size = s_->flow_controlled_buffer.length;
if (!grpc_stream_compress(s_->stream_compression_ctx, if (GPR_UNLIKELY(!grpc_stream_compress(
&s_->flow_controlled_buffer, s_->stream_compression_ctx, &s_->flow_controlled_buffer,
&s_->compressed_data_buffer, nullptr, MAX_SIZE_T, &s_->compressed_data_buffer, nullptr, MAX_SIZE_T,
GRPC_STREAM_COMPRESSION_FLUSH_SYNC)) { GRPC_STREAM_COMPRESSION_FLUSH_SYNC))) {
gpr_log(GPR_ERROR, "Stream compression failed."); gpr_log(GPR_ERROR, "Stream compression failed.");
} }
} }

@ -360,7 +360,7 @@ static void remove_from_storage(struct stream_obj* s,
s->storage.num_pending_ops); s->storage.num_pending_ops);
gpr_free(oas); gpr_free(oas);
break; break;
} else if (curr->next == nullptr) { } else if (GPR_UNLIKELY(curr->next == nullptr)) {
CRONET_LOG(GPR_ERROR, "Reached end of LL and did not find op to free"); CRONET_LOG(GPR_ERROR, "Reached end of LL and did not find op to free");
} }
} }
@ -1054,7 +1054,7 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) {
GPR_ASSERT(false); GPR_ASSERT(false);
} }
grpc_slice_buffer_add(&write_slice_buffer, slice); grpc_slice_buffer_add(&write_slice_buffer, slice);
if (write_slice_buffer.count != 1) { if (GPR_UNLIKELY(write_slice_buffer.count != 1)) {
/* Empty request not handled yet */ /* Empty request not handled yet */
gpr_log(GPR_ERROR, "Empty request is not supported"); gpr_log(GPR_ERROR, "Empty request is not supported");
GPR_ASSERT(write_slice_buffer.count == 1); GPR_ASSERT(write_slice_buffer.count == 1);
@ -1455,7 +1455,7 @@ grpc_transport* grpc_create_cronet_transport(void* engine, const char* target,
for (size_t i = 0; i < args->num_args; i++) { for (size_t i = 0; i < args->num_args; i++) {
if (0 == if (0 ==
strcmp(args->args[i].key, GRPC_ARG_USE_CRONET_PACKET_COALESCING)) { strcmp(args->args[i].key, GRPC_ARG_USE_CRONET_PACKET_COALESCING)) {
if (args->args[i].type != GRPC_ARG_INTEGER) { if (GPR_UNLIKELY(args->args[i].type != GRPC_ARG_INTEGER)) {
gpr_log(GPR_ERROR, "%s ignored: it must be an integer", gpr_log(GPR_ERROR, "%s ignored: it must be an integer",
GRPC_ARG_USE_CRONET_PACKET_COALESCING); GRPC_ARG_USE_CRONET_PACKET_COALESCING);
} else { } else {

Loading…
Cancel
Save