grpc 1.20.0 → 1.21.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (209) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +500 -29
  3. data/etc/roots.pem +146 -0
  4. data/include/grpc/grpc_security.h +1 -1
  5. data/include/grpc/impl/codegen/grpc_types.h +10 -7
  6. data/include/grpc/impl/codegen/port_platform.h +11 -1
  7. data/include/grpc/impl/codegen/slice.h +1 -21
  8. data/include/grpc/impl/codegen/status.h +2 -1
  9. data/include/grpc/slice.h +1 -1
  10. data/src/core/ext/filters/client_channel/backup_poller.cc +19 -13
  11. data/src/core/ext/filters/client_channel/backup_poller.h +3 -0
  12. data/src/core/ext/filters/client_channel/channel_connectivity.cc +1 -1
  13. data/src/core/ext/filters/client_channel/client_channel.cc +2084 -1673
  14. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +2 -3
  15. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +4 -0
  16. data/src/core/ext/filters/client_channel/health/health_check_client.cc +54 -49
  17. data/src/core/ext/filters/client_channel/health/health_check_client.h +20 -9
  18. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +1 -2
  19. data/src/core/ext/filters/client_channel/http_connect_handshaker.h +1 -1
  20. data/src/core/ext/filters/client_channel/lb_policy.cc +3 -30
  21. data/src/core/ext/filters/client_channel/lb_policy.h +16 -25
  22. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +106 -81
  23. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc +6 -2
  24. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +8 -12
  25. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +2 -2
  26. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +1 -1
  27. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +57 -49
  28. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +47 -41
  29. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +24 -20
  30. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +989 -284
  31. data/src/core/ext/filters/client_channel/lb_policy_factory.h +4 -1
  32. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +105 -2
  33. data/src/core/ext/filters/client_channel/lb_policy_registry.h +9 -2
  34. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +79 -36
  35. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +84 -2
  36. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +3 -0
  37. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc +179 -0
  38. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +15 -3
  39. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +80 -4
  40. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +7 -13
  41. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +2 -2
  42. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc +39 -0
  43. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc +0 -6
  44. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +2 -64
  45. data/src/core/ext/filters/client_channel/resolver/dns/dns_resolver_selection.cc +28 -0
  46. data/src/core/ext/filters/client_channel/resolver/dns/dns_resolver_selection.h +29 -0
  47. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +4 -4
  48. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +367 -232
  49. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +55 -76
  50. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +50 -39
  51. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +18 -12
  52. data/src/core/ext/filters/client_channel/service_config.cc +247 -27
  53. data/src/core/ext/filters/client_channel/service_config.h +119 -166
  54. data/src/core/ext/filters/client_channel/subchannel.cc +46 -84
  55. data/src/core/ext/filters/client_channel/subchannel.h +7 -7
  56. data/src/core/ext/filters/deadline/deadline_filter.cc +3 -4
  57. data/src/core/ext/filters/deadline/deadline_filter.h +3 -2
  58. data/src/core/ext/filters/http/client/http_client_filter.cc +7 -5
  59. data/src/core/ext/filters/http/client/http_client_filter.h +1 -1
  60. data/src/core/ext/filters/http/client_authority_filter.cc +1 -1
  61. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +4 -3
  62. data/src/core/ext/filters/http/server/http_server_filter.cc +18 -12
  63. data/src/core/ext/filters/message_size/message_size_filter.cc +118 -76
  64. data/src/core/ext/filters/message_size/message_size_filter.h +33 -0
  65. data/src/core/ext/transport/chttp2/alpn/alpn.h +1 -1
  66. data/src/core/ext/transport/chttp2/transport/chttp2_plugin.cc +9 -7
  67. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +93 -60
  68. data/src/core/ext/transport/chttp2/transport/flow_control.h +1 -1
  69. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +4 -3
  70. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +3 -3
  71. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +8 -2
  72. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +2 -2
  73. data/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +1 -1
  74. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +3 -2
  75. data/src/core/ext/transport/chttp2/transport/internal.h +35 -23
  76. data/src/core/ext/transport/chttp2/transport/parsing.cc +4 -4
  77. data/src/core/ext/transport/chttp2/transport/stream_lists.cc +3 -3
  78. data/src/core/ext/transport/chttp2/transport/writing.cc +61 -27
  79. data/src/core/ext/transport/inproc/inproc_transport.cc +18 -18
  80. data/src/core/lib/channel/channel_args.cc +0 -101
  81. data/src/core/lib/channel/channel_args.h +0 -37
  82. data/src/core/lib/channel/channel_stack.h +9 -5
  83. data/src/core/lib/channel/channelz_registry.cc +1 -1
  84. data/src/core/lib/channel/connected_channel.cc +2 -2
  85. data/src/core/lib/channel/context.h +3 -0
  86. data/src/core/lib/channel/handshaker.cc +4 -4
  87. data/src/core/lib/channel/handshaker.h +1 -1
  88. data/src/core/lib/compression/compression_args.cc +127 -0
  89. data/src/core/lib/compression/compression_args.h +55 -0
  90. data/src/core/lib/debug/trace.cc +13 -7
  91. data/src/core/lib/debug/trace.h +12 -0
  92. data/src/core/lib/gpr/arena.h +13 -9
  93. data/src/core/lib/gpr/env.h +2 -5
  94. data/src/core/lib/gpr/env_linux.cc +6 -1
  95. data/src/core/lib/gpr/env_posix.cc +5 -0
  96. data/src/core/lib/gpr/env_windows.cc +7 -5
  97. data/src/core/lib/gpr/log.cc +9 -13
  98. data/src/core/lib/gpr/string.cc +12 -6
  99. data/src/core/lib/gpr/string.h +4 -2
  100. data/src/core/lib/gpr/time_posix.cc +13 -0
  101. data/src/core/lib/gprpp/arena.cc +103 -0
  102. data/src/core/lib/gprpp/arena.h +121 -0
  103. data/src/core/lib/gprpp/fork.cc +12 -29
  104. data/src/core/lib/gprpp/global_config.h +87 -0
  105. data/src/core/lib/gprpp/global_config_custom.h +29 -0
  106. data/src/core/lib/gprpp/global_config_env.cc +135 -0
  107. data/src/core/lib/gprpp/global_config_env.h +131 -0
  108. data/src/core/lib/gprpp/global_config_generic.h +44 -0
  109. data/src/core/lib/gprpp/map.h +419 -0
  110. data/src/core/lib/gprpp/optional.h +1 -0
  111. data/src/core/lib/gprpp/orphanable.h +2 -2
  112. data/src/core/lib/gprpp/{mutex_lock.h → pair.h} +15 -19
  113. data/src/core/lib/gprpp/ref_counted.h +18 -2
  114. data/src/core/lib/gprpp/sync.h +126 -0
  115. data/src/core/lib/http/parser.cc +1 -1
  116. data/src/core/lib/iomgr/call_combiner.cc +84 -90
  117. data/src/core/lib/iomgr/call_combiner.h +75 -82
  118. data/src/core/lib/iomgr/cfstream_handle.cc +202 -0
  119. data/src/core/lib/iomgr/cfstream_handle.h +82 -0
  120. data/src/core/lib/iomgr/combiner.h +1 -1
  121. data/src/core/lib/iomgr/endpoint_cfstream.cc +375 -0
  122. data/src/core/lib/iomgr/endpoint_cfstream.h +49 -0
  123. data/src/core/lib/iomgr/endpoint_pair_windows.cc +2 -2
  124. data/src/core/lib/iomgr/error.h +23 -0
  125. data/src/core/lib/iomgr/error_cfstream.cc +52 -0
  126. data/src/core/lib/iomgr/error_cfstream.h +31 -0
  127. data/src/core/lib/iomgr/ev_epoll1_linux.cc +34 -27
  128. data/src/core/lib/iomgr/ev_epollex_linux.cc +33 -33
  129. data/src/core/lib/iomgr/ev_poll_posix.cc +7 -7
  130. data/src/core/lib/iomgr/ev_posix.cc +15 -13
  131. data/src/core/lib/iomgr/ev_posix.h +4 -1
  132. data/src/core/lib/iomgr/executor.cc +13 -9
  133. data/src/core/lib/iomgr/fork_posix.cc +0 -1
  134. data/src/core/lib/iomgr/internal_errqueue.cc +1 -1
  135. data/src/core/lib/iomgr/iomgr.cc +6 -5
  136. data/src/core/lib/iomgr/iomgr_custom.cc +3 -0
  137. data/src/core/lib/iomgr/iomgr_custom.h +2 -0
  138. data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +93 -0
  139. data/src/core/lib/iomgr/iomgr_windows.cc +1 -0
  140. data/src/core/lib/iomgr/lockfree_event.cc +3 -3
  141. data/src/core/lib/iomgr/port.h +11 -0
  142. data/src/core/lib/iomgr/resource_quota.cc +40 -37
  143. data/src/core/lib/iomgr/socket_utils_common_posix.cc +6 -2
  144. data/src/core/lib/iomgr/socket_windows.cc +19 -0
  145. data/src/core/lib/iomgr/socket_windows.h +8 -0
  146. data/src/core/lib/iomgr/tcp_client_cfstream.cc +216 -0
  147. data/src/core/lib/iomgr/tcp_client_custom.cc +2 -2
  148. data/src/core/lib/iomgr/tcp_client_posix.cc +3 -3
  149. data/src/core/lib/iomgr/tcp_client_windows.cc +1 -1
  150. data/src/core/lib/iomgr/tcp_custom.cc +9 -9
  151. data/src/core/lib/iomgr/tcp_posix.cc +41 -41
  152. data/src/core/lib/iomgr/tcp_server_custom.cc +3 -3
  153. data/src/core/lib/iomgr/tcp_server_posix.cc +14 -1
  154. data/src/core/lib/iomgr/tcp_server_windows.cc +2 -2
  155. data/src/core/lib/iomgr/tcp_windows.cc +7 -9
  156. data/src/core/lib/iomgr/timer_generic.cc +16 -16
  157. data/src/core/lib/iomgr/timer_manager.cc +12 -11
  158. data/src/core/lib/profiling/basic_timers.cc +10 -4
  159. data/src/core/lib/security/context/security_context.cc +6 -7
  160. data/src/core/lib/security/context/security_context.h +3 -4
  161. data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +1 -1
  162. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +2 -3
  163. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +1 -1
  164. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +7 -7
  165. data/src/core/lib/security/security_connector/load_system_roots_linux.cc +7 -5
  166. data/src/core/lib/security/security_connector/security_connector.cc +0 -1
  167. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +3 -2
  168. data/src/core/lib/security/security_connector/ssl_utils.cc +30 -26
  169. data/src/core/lib/security/security_connector/ssl_utils.h +5 -1
  170. data/src/core/lib/security/transport/client_auth_filter.cc +7 -11
  171. data/src/core/lib/security/transport/secure_endpoint.cc +4 -4
  172. data/src/core/lib/security/transport/server_auth_filter.cc +2 -3
  173. data/src/core/lib/slice/slice.cc +99 -116
  174. data/src/core/lib/slice/slice_buffer.cc +5 -0
  175. data/src/core/lib/slice/slice_intern.cc +38 -95
  176. data/src/core/lib/slice/slice_internal.h +200 -2
  177. data/src/core/lib/surface/api_trace.h +1 -1
  178. data/src/core/lib/surface/call.cc +41 -35
  179. data/src/core/lib/surface/call.h +7 -2
  180. data/src/core/lib/surface/call_details.cc +0 -1
  181. data/src/core/lib/surface/completion_queue.cc +36 -27
  182. data/src/core/lib/surface/init.cc +3 -4
  183. data/src/core/lib/surface/lame_client.cc +1 -1
  184. data/src/core/lib/surface/server.cc +18 -25
  185. data/src/core/lib/surface/version.cc +1 -1
  186. data/src/core/lib/transport/bdp_estimator.cc +3 -3
  187. data/src/core/lib/transport/bdp_estimator.h +2 -2
  188. data/src/core/lib/transport/connectivity_state.cc +10 -40
  189. data/src/core/lib/transport/connectivity_state.h +0 -8
  190. data/src/core/lib/transport/error_utils.cc +12 -0
  191. data/src/core/lib/transport/metadata.cc +206 -278
  192. data/src/core/lib/transport/metadata.h +205 -10
  193. data/src/core/lib/transport/static_metadata.cc +108 -116
  194. data/src/core/lib/transport/static_metadata.h +1 -2
  195. data/src/core/lib/transport/status_metadata.cc +3 -3
  196. data/src/core/lib/transport/transport.cc +29 -66
  197. data/src/core/lib/transport/transport.h +36 -8
  198. data/src/core/lib/transport/transport_impl.h +1 -1
  199. data/src/core/tsi/fake_transport_security.cc +4 -4
  200. data/src/core/tsi/ssl/session_cache/ssl_session_cache.cc +1 -1
  201. data/src/core/tsi/ssl_transport_security.cc +1 -1
  202. data/src/ruby/ext/grpc/rb_grpc.c +1 -1
  203. data/src/ruby/lib/grpc/errors.rb +22 -3
  204. data/src/ruby/lib/grpc/generic/bidi_call.rb +1 -1
  205. data/src/ruby/lib/grpc/generic/rpc_server.rb +1 -1
  206. data/src/ruby/lib/grpc/version.rb +1 -1
  207. data/src/ruby/spec/errors_spec.rb +141 -0
  208. metadata +57 -33
  209. data/src/core/lib/gpr/arena.cc +0 -192
@@ -32,75 +32,78 @@
32
32
  #include "src/core/lib/gpr/string.h"
33
33
  #include "src/core/lib/gprpp/ref_counted.h"
34
34
  #include "src/core/lib/gprpp/ref_counted_ptr.h"
35
+ #include "src/core/lib/surface/call.h"
35
36
  #include "src/core/lib/surface/channel_init.h"
36
37
 
37
- typedef struct {
38
- int max_send_size;
39
- int max_recv_size;
40
- } message_size_limits;
38
+ static void recv_message_ready(void* user_data, grpc_error* error);
39
+ static void recv_trailing_metadata_ready(void* user_data, grpc_error* error);
41
40
 
42
41
  namespace grpc_core {
43
- namespace {
44
-
45
- class MessageSizeLimits : public RefCounted<MessageSizeLimits> {
46
- public:
47
- static RefCountedPtr<MessageSizeLimits> CreateFromJson(const grpc_json* json);
48
-
49
- const message_size_limits& limits() const { return limits_; }
50
42
 
51
- private:
52
- // So New() can call our private ctor.
53
- template <typename T, typename... Args>
54
- friend T* grpc_core::New(Args&&... args);
55
-
56
- MessageSizeLimits(int max_send_size, int max_recv_size) {
57
- limits_.max_send_size = max_send_size;
58
- limits_.max_recv_size = max_recv_size;
59
- }
60
-
61
- message_size_limits limits_;
62
- };
43
+ namespace {
44
+ size_t g_message_size_parser_index;
45
+ } // namespace
63
46
 
64
- RefCountedPtr<MessageSizeLimits> MessageSizeLimits::CreateFromJson(
65
- const grpc_json* json) {
47
+ UniquePtr<ServiceConfig::ParsedConfig> MessageSizeParser::ParsePerMethodParams(
48
+ const grpc_json* json, grpc_error** error) {
49
+ GPR_DEBUG_ASSERT(error != nullptr && *error == GRPC_ERROR_NONE);
66
50
  int max_request_message_bytes = -1;
67
51
  int max_response_message_bytes = -1;
52
+ InlinedVector<grpc_error*, 4> error_list;
68
53
  for (grpc_json* field = json->child; field != nullptr; field = field->next) {
69
54
  if (field->key == nullptr) continue;
70
55
  if (strcmp(field->key, "maxRequestMessageBytes") == 0) {
71
- if (max_request_message_bytes >= 0) return nullptr; // Duplicate.
56
+ if (max_request_message_bytes >= 0) {
57
+ error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
58
+ "field:maxRequestMessageBytes error:Duplicate entry"));
59
+ } // Duplicate, continue parsing.
72
60
  if (field->type != GRPC_JSON_STRING && field->type != GRPC_JSON_NUMBER) {
73
- return nullptr;
61
+ error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
62
+ "field:maxRequestMessageBytes error:should be of type number"));
63
+ } else {
64
+ max_request_message_bytes = gpr_parse_nonnegative_int(field->value);
65
+ if (max_request_message_bytes == -1) {
66
+ error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
67
+ "field:maxRequestMessageBytes error:should be non-negative"));
68
+ }
74
69
  }
75
- max_request_message_bytes = gpr_parse_nonnegative_int(field->value);
76
- if (max_request_message_bytes == -1) return nullptr;
77
70
  } else if (strcmp(field->key, "maxResponseMessageBytes") == 0) {
78
- if (max_response_message_bytes >= 0) return nullptr; // Duplicate.
71
+ if (max_response_message_bytes >= 0) {
72
+ error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
73
+ "field:maxResponseMessageBytes error:Duplicate entry"));
74
+ } // Duplicate, continue parsing
79
75
  if (field->type != GRPC_JSON_STRING && field->type != GRPC_JSON_NUMBER) {
80
- return nullptr;
76
+ error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
77
+ "field:maxResponseMessageBytes error:should be of type number"));
78
+ } else {
79
+ max_response_message_bytes = gpr_parse_nonnegative_int(field->value);
80
+ if (max_response_message_bytes == -1) {
81
+ error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
82
+ "field:maxResponseMessageBytes error:should be non-negative"));
83
+ }
81
84
  }
82
- max_response_message_bytes = gpr_parse_nonnegative_int(field->value);
83
- if (max_response_message_bytes == -1) return nullptr;
84
85
  }
85
86
  }
86
- return MakeRefCounted<MessageSizeLimits>(max_request_message_bytes,
87
- max_response_message_bytes);
87
+ if (!error_list.empty()) {
88
+ *error = GRPC_ERROR_CREATE_FROM_VECTOR("Message size parser", &error_list);
89
+ return nullptr;
90
+ }
91
+ return UniquePtr<ServiceConfig::ParsedConfig>(New<MessageSizeParsedObject>(
92
+ max_request_message_bytes, max_response_message_bytes));
88
93
  }
89
94
 
90
- } // namespace
91
- } // namespace grpc_core
95
+ void MessageSizeParser::Register() {
96
+ g_message_size_parser_index = ServiceConfig::RegisterParser(
97
+ UniquePtr<ServiceConfig::Parser>(New<MessageSizeParser>()));
98
+ }
92
99
 
93
- static void recv_message_ready(void* user_data, grpc_error* error);
94
- static void recv_trailing_metadata_ready(void* user_data, grpc_error* error);
100
+ size_t MessageSizeParser::ParserIndex() { return g_message_size_parser_index; }
101
+ } // namespace grpc_core
95
102
 
96
103
  namespace {
97
-
98
104
  struct channel_data {
99
- message_size_limits limits;
100
- // Maps path names to refcounted_message_size_limits structs.
101
- grpc_core::RefCountedPtr<grpc_core::SliceHashTable<
102
- grpc_core::RefCountedPtr<grpc_core::MessageSizeLimits>>>
103
- method_limit_table;
105
+ grpc_core::MessageSizeParsedObject::message_size_limits limits;
106
+ grpc_core::RefCountedPtr<grpc_core::ServiceConfig> svc_cfg;
104
107
  };
105
108
 
106
109
  struct call_data {
@@ -116,29 +119,42 @@ struct call_data {
116
119
  // Note: Per-method config is only available on the client, so we
117
120
  // apply the max request size to the send limit and the max response
118
121
  // size to the receive limit.
119
- if (chand.method_limit_table != nullptr) {
120
- grpc_core::RefCountedPtr<grpc_core::MessageSizeLimits> limits =
121
- grpc_core::ServiceConfig::MethodConfigTableLookup(
122
- *chand.method_limit_table, args.path);
123
- if (limits != nullptr) {
124
- if (limits->limits().max_send_size >= 0 &&
125
- (limits->limits().max_send_size < this->limits.max_send_size ||
126
- this->limits.max_send_size < 0)) {
127
- this->limits.max_send_size = limits->limits().max_send_size;
128
- }
129
- if (limits->limits().max_recv_size >= 0 &&
130
- (limits->limits().max_recv_size < this->limits.max_recv_size ||
131
- this->limits.max_recv_size < 0)) {
132
- this->limits.max_recv_size = limits->limits().max_recv_size;
133
- }
122
+ const grpc_core::MessageSizeParsedObject* limits = nullptr;
123
+ grpc_core::ServiceConfig::CallData* svc_cfg_call_data = nullptr;
124
+ if (args.context != nullptr) {
125
+ svc_cfg_call_data = static_cast<grpc_core::ServiceConfig::CallData*>(
126
+ args.context[GRPC_SERVICE_CONFIG_CALL_DATA].value);
127
+ }
128
+ if (svc_cfg_call_data != nullptr) {
129
+ limits = static_cast<const grpc_core::MessageSizeParsedObject*>(
130
+ svc_cfg_call_data->GetMethodParsedObject(
131
+ grpc_core::MessageSizeParser::ParserIndex()));
132
+ } else if (chand.svc_cfg != nullptr) {
133
+ const auto* objs_vector =
134
+ chand.svc_cfg->GetMethodServiceConfigObjectsVector(args.path);
135
+ if (objs_vector != nullptr) {
136
+ limits = static_cast<const grpc_core::MessageSizeParsedObject*>(
137
+ (*objs_vector)[grpc_core::MessageSizeParser::ParserIndex()].get());
138
+ }
139
+ }
140
+ if (limits != nullptr) {
141
+ if (limits->limits().max_send_size >= 0 &&
142
+ (limits->limits().max_send_size < this->limits.max_send_size ||
143
+ this->limits.max_send_size < 0)) {
144
+ this->limits.max_send_size = limits->limits().max_send_size;
145
+ }
146
+ if (limits->limits().max_recv_size >= 0 &&
147
+ (limits->limits().max_recv_size < this->limits.max_recv_size ||
148
+ this->limits.max_recv_size < 0)) {
149
+ this->limits.max_recv_size = limits->limits().max_recv_size;
134
150
  }
135
151
  }
136
152
  }
137
153
 
138
154
  ~call_data() { GRPC_ERROR_UNREF(error); }
139
155
 
140
- grpc_call_combiner* call_combiner;
141
- message_size_limits limits;
156
+ grpc_core::CallCombiner* call_combiner;
157
+ grpc_core::MessageSizeParsedObject::message_size_limits limits;
142
158
  // Receive closures are chained: we inject this closure as the
143
159
  // recv_message_ready up-call on transport_stream_op, and remember to
144
160
  // call our next_recv_message_ready member after handling it.
@@ -284,9 +300,9 @@ static int default_size(const grpc_channel_args* args,
284
300
  return without_minimal_stack;
285
301
  }
286
302
 
287
- message_size_limits get_message_size_limits(
303
+ grpc_core::MessageSizeParsedObject::message_size_limits get_message_size_limits(
288
304
  const grpc_channel_args* channel_args) {
289
- message_size_limits lim;
305
+ grpc_core::MessageSizeParsedObject::message_size_limits lim;
290
306
  lim.max_send_size =
291
307
  default_size(channel_args, GRPC_DEFAULT_MAX_SEND_MESSAGE_LENGTH);
292
308
  lim.max_recv_size =
@@ -313,18 +329,27 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem,
313
329
  grpc_channel_element_args* args) {
314
330
  GPR_ASSERT(!args->is_last);
315
331
  channel_data* chand = static_cast<channel_data*>(elem->channel_data);
332
+ new (chand) channel_data();
316
333
  chand->limits = get_message_size_limits(args->channel_args);
317
- // Get method config table from channel args.
334
+ // TODO(yashykt): We only need to read GRPC_ARG_SERVICE_CONFIG in the case of
335
+ // direct channels. (Service config is otherwise stored in the call_context by
336
+ // client_channel filter.) If we ever need a second filter that also needs to
337
+ // parse GRPC_ARG_SERVICE_CONFIG, we should refactor this code and add a
338
+ // separate filter that reads GRPC_ARG_SERVICE_CONFIG and saves the parsed
339
+ // config in the call_context.
318
340
  const grpc_arg* channel_arg =
319
341
  grpc_channel_args_find(args->channel_args, GRPC_ARG_SERVICE_CONFIG);
320
342
  const char* service_config_str = grpc_channel_arg_get_string(channel_arg);
321
343
  if (service_config_str != nullptr) {
322
- grpc_core::RefCountedPtr<grpc_core::ServiceConfig> service_config =
323
- grpc_core::ServiceConfig::Create(service_config_str);
324
- if (service_config != nullptr) {
325
- chand->method_limit_table = service_config->CreateMethodConfigTable(
326
- grpc_core::MessageSizeLimits::CreateFromJson);
344
+ grpc_error* service_config_error = GRPC_ERROR_NONE;
345
+ auto svc_cfg = grpc_core::ServiceConfig::Create(service_config_str,
346
+ &service_config_error);
347
+ if (service_config_error == GRPC_ERROR_NONE) {
348
+ chand->svc_cfg = std::move(svc_cfg);
349
+ } else {
350
+ gpr_log(GPR_ERROR, "%s", grpc_error_string(service_config_error));
327
351
  }
352
+ GRPC_ERROR_UNREF(service_config_error);
328
353
  }
329
354
  return GRPC_ERROR_NONE;
330
355
  }
@@ -332,7 +357,7 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem,
332
357
  // Destructor for channel_data.
333
358
  static void destroy_channel_elem(grpc_channel_element* elem) {
334
359
  channel_data* chand = static_cast<channel_data*>(elem->channel_data);
335
- chand->method_limit_table.reset();
360
+ chand->~channel_data();
336
361
  }
337
362
 
338
363
  const grpc_channel_filter grpc_message_size_filter = {
@@ -348,18 +373,34 @@ const grpc_channel_filter grpc_message_size_filter = {
348
373
  grpc_channel_next_get_info,
349
374
  "message_size"};
350
375
 
376
+ // Used for GRPC_CLIENT_SUBCHANNEL
377
+ static bool maybe_add_message_size_filter_subchannel(
378
+ grpc_channel_stack_builder* builder, void* arg) {
379
+ const grpc_channel_args* channel_args =
380
+ grpc_channel_stack_builder_get_channel_arguments(builder);
381
+ if (grpc_channel_args_want_minimal_stack(channel_args)) {
382
+ return true;
383
+ }
384
+ return grpc_channel_stack_builder_prepend_filter(
385
+ builder, &grpc_message_size_filter, nullptr, nullptr);
386
+ }
387
+
388
+ // Used for GRPC_CLIENT_DIRECT_CHANNEL and GRPC_SERVER_CHANNEL. Adds the filter
389
+ // only if message size limits or service config is specified.
351
390
  static bool maybe_add_message_size_filter(grpc_channel_stack_builder* builder,
352
391
  void* arg) {
353
392
  const grpc_channel_args* channel_args =
354
393
  grpc_channel_stack_builder_get_channel_arguments(builder);
355
394
  bool enable = false;
356
- message_size_limits lim = get_message_size_limits(channel_args);
395
+ grpc_core::MessageSizeParsedObject::message_size_limits lim =
396
+ get_message_size_limits(channel_args);
357
397
  if (lim.max_send_size != -1 || lim.max_recv_size != -1) {
358
398
  enable = true;
359
399
  }
360
400
  const grpc_arg* a =
361
401
  grpc_channel_args_find(channel_args, GRPC_ARG_SERVICE_CONFIG);
362
- if (a != nullptr) {
402
+ const char* svc_cfg_str = grpc_channel_arg_get_string(a);
403
+ if (svc_cfg_str != nullptr) {
363
404
  enable = true;
364
405
  }
365
406
  if (enable) {
@@ -371,15 +412,16 @@ static bool maybe_add_message_size_filter(grpc_channel_stack_builder* builder,
371
412
  }
372
413
 
373
414
  void grpc_message_size_filter_init(void) {
374
- grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL,
375
- GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
376
- maybe_add_message_size_filter, nullptr);
415
+ grpc_channel_init_register_stage(
416
+ GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
417
+ maybe_add_message_size_filter_subchannel, nullptr);
377
418
  grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL,
378
419
  GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
379
420
  maybe_add_message_size_filter, nullptr);
380
421
  grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL,
381
422
  GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
382
423
  maybe_add_message_size_filter, nullptr);
424
+ grpc_core::MessageSizeParser::Register();
383
425
  }
384
426
 
385
427
  void grpc_message_size_filter_shutdown(void) {}
@@ -19,8 +19,41 @@
19
19
 
20
20
  #include <grpc/support/port_platform.h>
21
21
 
22
+ #include "src/core/ext/filters/client_channel/service_config.h"
22
23
  #include "src/core/lib/channel/channel_stack.h"
23
24
 
24
25
  extern const grpc_channel_filter grpc_message_size_filter;
25
26
 
27
+ namespace grpc_core {
28
+
29
+ class MessageSizeParsedObject : public ServiceConfig::ParsedConfig {
30
+ public:
31
+ struct message_size_limits {
32
+ int max_send_size;
33
+ int max_recv_size;
34
+ };
35
+
36
+ MessageSizeParsedObject(int max_send_size, int max_recv_size) {
37
+ limits_.max_send_size = max_send_size;
38
+ limits_.max_recv_size = max_recv_size;
39
+ }
40
+
41
+ const message_size_limits& limits() const { return limits_; }
42
+
43
+ private:
44
+ message_size_limits limits_;
45
+ };
46
+
47
+ class MessageSizeParser : public ServiceConfig::Parser {
48
+ public:
49
+ UniquePtr<ServiceConfig::ParsedConfig> ParsePerMethodParams(
50
+ const grpc_json* json, grpc_error** error) override;
51
+
52
+ static void Register();
53
+
54
+ static size_t ParserIndex();
55
+ };
56
+
57
+ } // namespace grpc_core
58
+
26
59
  #endif /* GRPC_CORE_EXT_FILTERS_MESSAGE_SIZE_MESSAGE_SIZE_FILTER_H */
@@ -23,7 +23,7 @@
23
23
 
24
24
  #include <string.h>
25
25
 
26
- /* Retuns 1 if the version is supported, 0 otherwise. */
26
+ /* Returns 1 if the version is supported, 0 otherwise. */
27
27
  int grpc_chttp2_is_alpn_version_supported(const char* version, size_t size);
28
28
 
29
29
  /* Returns the number of protocol versions to advertise */
@@ -20,16 +20,18 @@
20
20
 
21
21
  #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
22
22
  #include "src/core/lib/debug/trace.h"
23
- #include "src/core/lib/gpr/env.h"
23
+ #include "src/core/lib/gprpp/global_config.h"
24
24
  #include "src/core/lib/transport/metadata.h"
25
25
 
26
+ GPR_GLOBAL_CONFIG_DEFINE_BOOL(
27
+ grpc_experimental_disable_flow_control, false,
28
+ "If set, flow control will be effectively disabled. Max out all values and "
29
+ "assume the remote peer does the same. Thus we can ignore any flow control "
30
+ "bookkeeping, error checking, and decision making");
31
+
26
32
  void grpc_chttp2_plugin_init(void) {
27
- g_flow_control_enabled = true;
28
- char* env_variable = gpr_getenv("GRPC_EXPERIMENTAL_DISABLE_FLOW_CONTROL");
29
- if (env_variable != nullptr) {
30
- g_flow_control_enabled = false;
31
- gpr_free(env_variable);
32
- }
33
+ g_flow_control_enabled =
34
+ !GPR_GLOBAL_CONFIG_GET(grpc_experimental_disable_flow_control);
33
35
  }
34
36
 
35
37
  void grpc_chttp2_plugin_shutdown(void) {}
@@ -119,7 +119,7 @@ static void maybe_start_some_streams(grpc_chttp2_transport* t);
119
119
 
120
120
  static void connectivity_state_set(grpc_chttp2_transport* t,
121
121
  grpc_connectivity_state state,
122
- grpc_error* error, const char* reason);
122
+ const char* reason);
123
123
 
124
124
  static void benign_reclaimer_locked(void* t, grpc_error* error);
125
125
  static void destructive_reclaimer_locked(void* t, grpc_error* error);
@@ -592,8 +592,7 @@ static void close_transport_locked(grpc_chttp2_transport* t,
592
592
  }
593
593
  GPR_ASSERT(error != GRPC_ERROR_NONE);
594
594
  t->closed_with_error = GRPC_ERROR_REF(error);
595
- connectivity_state_set(t, GRPC_CHANNEL_SHUTDOWN, GRPC_ERROR_REF(error),
596
- "close_transport");
595
+ connectivity_state_set(t, GRPC_CHANNEL_SHUTDOWN, "close_transport");
597
596
  if (t->ping_state.is_delayed_ping_timer_set) {
598
597
  grpc_timer_cancel(&t->ping_state.delayed_ping_timer);
599
598
  }
@@ -645,17 +644,23 @@ void grpc_chttp2_stream_unref(grpc_chttp2_stream* s) {
645
644
  }
646
645
  #endif
647
646
 
648
- grpc_chttp2_stream::grpc_chttp2_stream(grpc_chttp2_transport* t,
649
- grpc_stream_refcount* refcount,
650
- const void* server_data,
651
- gpr_arena* arena)
652
- : t(t), refcount(refcount), metadata_buffer{{arena}, {arena}} {
647
+ grpc_chttp2_stream::Reffer::Reffer(grpc_chttp2_stream* s) {
653
648
  /* We reserve one 'active stream' that's dropped when the stream is
654
649
  read-closed. The others are for Chttp2IncomingByteStreams that are
655
650
  actively reading */
656
- GRPC_CHTTP2_STREAM_REF(this, "chttp2");
657
- GRPC_CHTTP2_REF_TRANSPORT(t, "stream");
651
+ GRPC_CHTTP2_STREAM_REF(s, "chttp2");
652
+ GRPC_CHTTP2_REF_TRANSPORT(s->t, "stream");
653
+ }
658
654
 
655
+ grpc_chttp2_stream::grpc_chttp2_stream(grpc_chttp2_transport* t,
656
+ grpc_stream_refcount* refcount,
657
+ const void* server_data,
658
+ grpc_core::Arena* arena)
659
+ : t(t),
660
+ refcount(refcount),
661
+ reffer(this),
662
+ metadata_buffer{grpc_chttp2_incoming_metadata_buffer(arena),
663
+ grpc_chttp2_incoming_metadata_buffer(arena)} {
659
664
  if (server_data) {
660
665
  id = static_cast<uint32_t>((uintptr_t)server_data);
661
666
  *t->accepting_stream = this;
@@ -674,8 +679,6 @@ grpc_chttp2_stream::grpc_chttp2_stream(grpc_chttp2_transport* t,
674
679
  grpc_slice_buffer_init(&frame_storage);
675
680
  grpc_slice_buffer_init(&unprocessed_incoming_frames_buffer);
676
681
  grpc_slice_buffer_init(&flow_controlled_buffer);
677
- grpc_slice_buffer_init(&compressed_data_buffer);
678
- grpc_slice_buffer_init(&decompressed_data_buffer);
679
682
 
680
683
  GRPC_CLOSURE_INIT(&complete_fetch_locked, ::complete_fetch_locked, this,
681
684
  grpc_combiner_scheduler(t->combiner));
@@ -699,8 +702,13 @@ grpc_chttp2_stream::~grpc_chttp2_stream() {
699
702
 
700
703
  grpc_slice_buffer_destroy_internal(&unprocessed_incoming_frames_buffer);
701
704
  grpc_slice_buffer_destroy_internal(&frame_storage);
702
- grpc_slice_buffer_destroy_internal(&compressed_data_buffer);
703
- grpc_slice_buffer_destroy_internal(&decompressed_data_buffer);
705
+ if (stream_compression_method != GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS) {
706
+ grpc_slice_buffer_destroy_internal(&compressed_data_buffer);
707
+ }
708
+ if (stream_decompression_method !=
709
+ GRPC_STREAM_COMPRESSION_IDENTITY_DECOMPRESS) {
710
+ grpc_slice_buffer_destroy_internal(&decompressed_data_buffer);
711
+ }
704
712
 
705
713
  grpc_chttp2_list_remove_stalled_by_transport(t, this);
706
714
  grpc_chttp2_list_remove_stalled_by_stream(t, this);
@@ -736,7 +744,7 @@ grpc_chttp2_stream::~grpc_chttp2_stream() {
736
744
 
737
745
  static int init_stream(grpc_transport* gt, grpc_stream* gs,
738
746
  grpc_stream_refcount* refcount, const void* server_data,
739
- gpr_arena* arena) {
747
+ grpc_core::Arena* arena) {
740
748
  GPR_TIMER_SCOPE("init_stream", 0);
741
749
  grpc_chttp2_transport* t = reinterpret_cast<grpc_chttp2_transport*>(gt);
742
750
  new (gs) grpc_chttp2_stream(t, refcount, server_data, arena);
@@ -754,12 +762,15 @@ static void destroy_stream(grpc_transport* gt, grpc_stream* gs,
754
762
  GPR_TIMER_SCOPE("destroy_stream", 0);
755
763
  grpc_chttp2_transport* t = reinterpret_cast<grpc_chttp2_transport*>(gt);
756
764
  grpc_chttp2_stream* s = reinterpret_cast<grpc_chttp2_stream*>(gs);
757
-
758
- if (s->stream_compression_ctx != nullptr) {
765
+ if (s->stream_compression_method !=
766
+ GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS &&
767
+ s->stream_compression_ctx != nullptr) {
759
768
  grpc_stream_compression_context_destroy(s->stream_compression_ctx);
760
769
  s->stream_compression_ctx = nullptr;
761
770
  }
762
- if (s->stream_decompression_ctx != nullptr) {
771
+ if (s->stream_decompression_method !=
772
+ GRPC_STREAM_COMPRESSION_IDENTITY_DECOMPRESS &&
773
+ s->stream_decompression_ctx != nullptr) {
763
774
  grpc_stream_compression_context_destroy(s->stream_decompression_ctx);
764
775
  s->stream_decompression_ctx = nullptr;
765
776
  }
@@ -1166,8 +1177,7 @@ void grpc_chttp2_add_incoming_goaway(grpc_chttp2_transport* t,
1166
1177
 
1167
1178
  /* lie: use transient failure from the transport to indicate goaway has been
1168
1179
  * received */
1169
- connectivity_state_set(t, GRPC_CHANNEL_TRANSIENT_FAILURE,
1170
- GRPC_ERROR_REF(t->goaway_error), "got_goaway");
1180
+ connectivity_state_set(t, GRPC_CHANNEL_TRANSIENT_FAILURE, "got_goaway");
1171
1181
  }
1172
1182
 
1173
1183
  static void maybe_start_some_streams(grpc_chttp2_transport* t) {
@@ -1189,10 +1199,8 @@ static void maybe_start_some_streams(grpc_chttp2_transport* t) {
1189
1199
  t->next_stream_id += 2;
1190
1200
 
1191
1201
  if (t->next_stream_id >= MAX_CLIENT_STREAM_ID) {
1192
- connectivity_state_set(
1193
- t, GRPC_CHANNEL_TRANSIENT_FAILURE,
1194
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("Stream IDs exhausted"),
1195
- "no_more_stream_ids");
1202
+ connectivity_state_set(t, GRPC_CHANNEL_TRANSIENT_FAILURE,
1203
+ "no_more_stream_ids");
1196
1204
  }
1197
1205
 
1198
1206
  grpc_chttp2_stream_map_add(&t->stream_map, s->id, s);
@@ -1241,7 +1249,7 @@ void grpc_chttp2_complete_closure_step(grpc_chttp2_transport* t,
1241
1249
  return;
1242
1250
  }
1243
1251
  closure->next_data.scratch -= CLOSURE_BARRIER_FIRST_REF_BIT;
1244
- if (grpc_http_trace.enabled()) {
1252
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) {
1245
1253
  const char* errstr = grpc_error_string(error);
1246
1254
  gpr_log(
1247
1255
  GPR_INFO,
@@ -1280,8 +1288,8 @@ void grpc_chttp2_complete_closure_step(grpc_chttp2_transport* t,
1280
1288
 
1281
1289
  static bool contains_non_ok_status(grpc_metadata_batch* batch) {
1282
1290
  if (batch->idx.named.grpc_status != nullptr) {
1283
- return !grpc_mdelem_eq(batch->idx.named.grpc_status->md,
1284
- GRPC_MDELEM_GRPC_STATUS_0);
1291
+ return !grpc_mdelem_static_value_eq(batch->idx.named.grpc_status->md,
1292
+ GRPC_MDELEM_GRPC_STATUS_0);
1285
1293
  }
1286
1294
  return false;
1287
1295
  }
@@ -1393,7 +1401,7 @@ static void perform_stream_op_locked(void* stream_op,
1393
1401
 
1394
1402
  s->context = op->payload->context;
1395
1403
  s->traced = op->is_traced;
1396
- if (grpc_http_trace.enabled()) {
1404
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) {
1397
1405
  char* str = grpc_transport_stream_op_batch_string(op);
1398
1406
  gpr_log(GPR_INFO, "perform_stream_op_locked: %s; on_complete = %p", str,
1399
1407
  op->on_complete);
@@ -1412,7 +1420,7 @@ static void perform_stream_op_locked(void* stream_op,
1412
1420
  // on_complete will be null if and only if there are no send ops in the batch.
1413
1421
  if (on_complete != nullptr) {
1414
1422
  // This batch has send ops. Use final_data as a barrier until enqueue time;
1415
- // the inital counter is dropped at the end of this function.
1423
+ // the initial counter is dropped at the end of this function.
1416
1424
  on_complete->next_data.scratch = CLOSURE_BARRIER_FIRST_REF_BIT;
1417
1425
  on_complete->error_data.error = GRPC_ERROR_NONE;
1418
1426
  }
@@ -1440,7 +1448,12 @@ static void perform_stream_op_locked(void* stream_op,
1440
1448
  true, &s->stream_compression_method) == 0) {
1441
1449
  s->stream_compression_method = GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS;
1442
1450
  }
1443
-
1451
+ if (s->stream_compression_method !=
1452
+ GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS) {
1453
+ s->uncompressed_data_size = 0;
1454
+ s->stream_compression_ctx = nullptr;
1455
+ grpc_slice_buffer_init(&s->compressed_data_buffer);
1456
+ }
1444
1457
  s->send_initial_metadata_finished = add_closure_barrier(on_complete);
1445
1458
  s->send_initial_metadata =
1446
1459
  op_payload->send_initial_metadata.send_initial_metadata;
@@ -1692,7 +1705,7 @@ static void perform_stream_op(grpc_transport* gt, grpc_stream* gs,
1692
1705
  }
1693
1706
  }
1694
1707
 
1695
- if (grpc_http_trace.enabled()) {
1708
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) {
1696
1709
  char* str = grpc_transport_stream_op_batch_string(op);
1697
1710
  gpr_log(GPR_INFO, "perform_stream_op[s=%p]: %s", s, str);
1698
1711
  gpr_free(str);
@@ -1859,7 +1872,7 @@ static void perform_transport_op_locked(void* stream_op,
1859
1872
 
1860
1873
  static void perform_transport_op(grpc_transport* gt, grpc_transport_op* op) {
1861
1874
  grpc_chttp2_transport* t = reinterpret_cast<grpc_chttp2_transport*>(gt);
1862
- if (grpc_http_trace.enabled()) {
1875
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) {
1863
1876
  char* msg = grpc_transport_op_string(op);
1864
1877
  gpr_log(GPR_INFO, "perform_transport_op[t=%p]: %s", t, msg);
1865
1878
  gpr_free(msg);
@@ -1996,27 +2009,39 @@ void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_chttp2_transport* t,
1996
2009
  !s->seen_error && s->recv_trailing_metadata_finished != nullptr) {
1997
2010
  /* Maybe some SYNC_FLUSH data is left in frame_storage. Consume them and
1998
2011
  * maybe decompress the next 5 bytes in the stream. */
1999
- bool end_of_context;
2000
- if (!s->stream_decompression_ctx) {
2001
- s->stream_decompression_ctx = grpc_stream_compression_context_create(
2002
- s->stream_decompression_method);
2003
- }
2004
- if (!grpc_stream_decompress(
2005
- s->stream_decompression_ctx, &s->frame_storage,
2006
- &s->unprocessed_incoming_frames_buffer, nullptr,
2007
- GRPC_HEADER_SIZE_IN_BYTES, &end_of_context)) {
2008
- grpc_slice_buffer_reset_and_unref_internal(&s->frame_storage);
2009
- grpc_slice_buffer_reset_and_unref_internal(
2010
- &s->unprocessed_incoming_frames_buffer);
2011
- s->seen_error = true;
2012
- } else {
2012
+ if (s->stream_decompression_method ==
2013
+ GRPC_STREAM_COMPRESSION_IDENTITY_DECOMPRESS) {
2014
+ grpc_slice_buffer_move_first(&s->frame_storage,
2015
+ GRPC_HEADER_SIZE_IN_BYTES,
2016
+ &s->unprocessed_incoming_frames_buffer);
2013
2017
  if (s->unprocessed_incoming_frames_buffer.length > 0) {
2014
2018
  s->unprocessed_incoming_frames_decompressed = true;
2015
2019
  pending_data = true;
2016
2020
  }
2017
- if (end_of_context) {
2018
- grpc_stream_compression_context_destroy(s->stream_decompression_ctx);
2019
- s->stream_decompression_ctx = nullptr;
2021
+ } else {
2022
+ bool end_of_context;
2023
+ if (!s->stream_decompression_ctx) {
2024
+ s->stream_decompression_ctx = grpc_stream_compression_context_create(
2025
+ s->stream_decompression_method);
2026
+ }
2027
+ if (!grpc_stream_decompress(
2028
+ s->stream_decompression_ctx, &s->frame_storage,
2029
+ &s->unprocessed_incoming_frames_buffer, nullptr,
2030
+ GRPC_HEADER_SIZE_IN_BYTES, &end_of_context)) {
2031
+ grpc_slice_buffer_reset_and_unref_internal(&s->frame_storage);
2032
+ grpc_slice_buffer_reset_and_unref_internal(
2033
+ &s->unprocessed_incoming_frames_buffer);
2034
+ s->seen_error = true;
2035
+ } else {
2036
+ if (s->unprocessed_incoming_frames_buffer.length > 0) {
2037
+ s->unprocessed_incoming_frames_decompressed = true;
2038
+ pending_data = true;
2039
+ }
2040
+ if (end_of_context) {
2041
+ grpc_stream_compression_context_destroy(
2042
+ s->stream_decompression_ctx);
2043
+ s->stream_decompression_ctx = nullptr;
2044
+ }
2020
2045
  }
2021
2046
  }
2022
2047
  }
@@ -2594,10 +2619,13 @@ static void schedule_bdp_ping_locked(grpc_chttp2_transport* t) {
2594
2619
 
2595
2620
  static void start_bdp_ping_locked(void* tp, grpc_error* error) {
2596
2621
  grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(tp);
2597
- if (grpc_http_trace.enabled()) {
2622
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) {
2598
2623
  gpr_log(GPR_INFO, "%s: Start BDP ping err=%s", t->peer_string,
2599
2624
  grpc_error_string(error));
2600
2625
  }
2626
+ if (error != GRPC_ERROR_NONE || t->closed_with_error != GRPC_ERROR_NONE) {
2627
+ return;
2628
+ }
2601
2629
  /* Reset the keepalive ping timer */
2602
2630
  if (t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_WAITING) {
2603
2631
  grpc_timer_cancel(&t->keepalive_ping_timer);
@@ -2607,11 +2635,11 @@ static void start_bdp_ping_locked(void* tp, grpc_error* error) {
2607
2635
 
2608
2636
  static void finish_bdp_ping_locked(void* tp, grpc_error* error) {
2609
2637
  grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(tp);
2610
- if (grpc_http_trace.enabled()) {
2638
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) {
2611
2639
  gpr_log(GPR_INFO, "%s: Complete BDP ping err=%s", t->peer_string,
2612
2640
  grpc_error_string(error));
2613
2641
  }
2614
- if (error != GRPC_ERROR_NONE) {
2642
+ if (error != GRPC_ERROR_NONE || t->closed_with_error != GRPC_ERROR_NONE) {
2615
2643
  GRPC_CHTTP2_UNREF_TRANSPORT(t, "bdp_ping");
2616
2644
  return;
2617
2645
  }
@@ -2739,7 +2767,7 @@ static void start_keepalive_ping_locked(void* arg, grpc_error* error) {
2739
2767
  if (t->channelz_socket != nullptr) {
2740
2768
  t->channelz_socket->RecordKeepaliveSent();
2741
2769
  }
2742
- if (grpc_http_trace.enabled()) {
2770
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) {
2743
2771
  gpr_log(GPR_INFO, "%s: Start keepalive ping", t->peer_string);
2744
2772
  }
2745
2773
  GRPC_CHTTP2_REF_TRANSPORT(t, "keepalive watchdog");
@@ -2752,7 +2780,7 @@ static void finish_keepalive_ping_locked(void* arg, grpc_error* error) {
2752
2780
  grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(arg);
2753
2781
  if (t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_PINGING) {
2754
2782
  if (error == GRPC_ERROR_NONE) {
2755
- if (grpc_http_trace.enabled()) {
2783
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) {
2756
2784
  gpr_log(GPR_INFO, "%s: Finish keepalive ping", t->peer_string);
2757
2785
  }
2758
2786
  t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_WAITING;
@@ -2796,9 +2824,9 @@ static void keepalive_watchdog_fired_locked(void* arg, grpc_error* error) {
2796
2824
 
2797
2825
  static void connectivity_state_set(grpc_chttp2_transport* t,
2798
2826
  grpc_connectivity_state state,
2799
- grpc_error* error, const char* reason) {
2827
+ const char* reason) {
2800
2828
  GRPC_CHTTP2_IF_TRACING(gpr_log(GPR_INFO, "set connectivity_state=%d", state));
2801
- grpc_connectivity_state_set(&t->channel_callback.state_tracker, state, error,
2829
+ grpc_connectivity_state_set(&t->channel_callback.state_tracker, state,
2802
2830
  reason);
2803
2831
  }
2804
2832
 
@@ -2936,6 +2964,8 @@ bool Chttp2IncomingByteStream::Next(size_t max_size_hint,
2936
2964
  }
2937
2965
 
2938
2966
  void Chttp2IncomingByteStream::MaybeCreateStreamDecompressionCtx() {
2967
+ GPR_DEBUG_ASSERT(stream_->stream_decompression_method !=
2968
+ GRPC_STREAM_COMPRESSION_IDENTITY_DECOMPRESS);
2939
2969
  if (!stream_->stream_decompression_ctx) {
2940
2970
  stream_->stream_decompression_ctx = grpc_stream_compression_context_create(
2941
2971
  stream_->stream_decompression_method);
@@ -2946,7 +2976,9 @@ grpc_error* Chttp2IncomingByteStream::Pull(grpc_slice* slice) {
2946
2976
  GPR_TIMER_SCOPE("incoming_byte_stream_pull", 0);
2947
2977
  grpc_error* error;
2948
2978
  if (stream_->unprocessed_incoming_frames_buffer.length > 0) {
2949
- if (!stream_->unprocessed_incoming_frames_decompressed) {
2979
+ if (!stream_->unprocessed_incoming_frames_decompressed &&
2980
+ stream_->stream_decompression_method !=
2981
+ GRPC_STREAM_COMPRESSION_IDENTITY_DECOMPRESS) {
2950
2982
  bool end_of_context;
2951
2983
  MaybeCreateStreamDecompressionCtx();
2952
2984
  if (!grpc_stream_decompress(stream_->stream_decompression_ctx,
@@ -3058,7 +3090,7 @@ static void benign_reclaimer_locked(void* arg, grpc_error* error) {
3058
3090
  grpc_chttp2_stream_map_size(&t->stream_map) == 0) {
3059
3091
  /* Channel with no active streams: send a goaway to try and make it
3060
3092
  * disconnect cleanly */
3061
- if (grpc_resource_quota_trace.enabled()) {
3093
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) {
3062
3094
  gpr_log(GPR_INFO, "HTTP2: %s - send goaway to free memory",
3063
3095
  t->peer_string);
3064
3096
  }
@@ -3066,7 +3098,8 @@ static void benign_reclaimer_locked(void* arg, grpc_error* error) {
3066
3098
  grpc_error_set_int(
3067
3099
  GRPC_ERROR_CREATE_FROM_STATIC_STRING("Buffers full"),
3068
3100
  GRPC_ERROR_INT_HTTP2_ERROR, GRPC_HTTP2_ENHANCE_YOUR_CALM));
3069
- } else if (error == GRPC_ERROR_NONE && grpc_resource_quota_trace.enabled()) {
3101
+ } else if (error == GRPC_ERROR_NONE &&
3102
+ GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) {
3070
3103
  gpr_log(GPR_INFO,
3071
3104
  "HTTP2: %s - skip benign reclamation, there are still %" PRIdPTR
3072
3105
  " streams",
@@ -3087,7 +3120,7 @@ static void destructive_reclaimer_locked(void* arg, grpc_error* error) {
3087
3120
  if (error == GRPC_ERROR_NONE && n > 0) {
3088
3121
  grpc_chttp2_stream* s = static_cast<grpc_chttp2_stream*>(
3089
3122
  grpc_chttp2_stream_map_rand(&t->stream_map));
3090
- if (grpc_resource_quota_trace.enabled()) {
3123
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) {
3091
3124
  gpr_log(GPR_INFO, "HTTP2: %s - abandon stream id %d", t->peer_string,
3092
3125
  s->id);
3093
3126
  }