grpc 1.57.0 → 1.58.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (402) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +534 -284
  3. data/include/grpc/event_engine/event_engine.h +0 -1
  4. data/include/grpc/event_engine/memory_allocator.h +2 -2
  5. data/include/grpc/impl/channel_arg_names.h +371 -0
  6. data/include/grpc/impl/grpc_types.h +1 -353
  7. data/include/grpc/module.modulemap +1 -0
  8. data/src/core/ext/filters/backend_metrics/backend_metric_filter.cc +1 -1
  9. data/src/core/ext/filters/channel_idle/channel_idle_filter.cc +2 -1
  10. data/src/core/ext/filters/client_channel/client_channel.cc +7 -3
  11. data/src/core/ext/filters/client_channel/http_proxy.cc +1 -1
  12. data/src/core/ext/filters/client_channel/lb_policy/address_filtering.cc +10 -5
  13. data/src/core/ext/filters/client_channel/lb_policy/address_filtering.h +7 -5
  14. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +1 -0
  15. data/src/core/ext/filters/client_channel/lb_policy/health_check_client.cc +5 -3
  16. data/src/core/ext/filters/client_channel/lb_policy/oob_backend_metric.cc +4 -2
  17. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +115 -109
  18. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.h +0 -5
  19. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +7 -2
  20. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc +2 -1
  21. data/src/core/ext/filters/client_channel/lb_policy/rls/rls.cc +1 -0
  22. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +1 -1
  23. data/src/core/ext/filters/client_channel/lb_policy/weighted_round_robin/weighted_round_robin.cc +11 -3
  24. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +6 -1
  25. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +8 -5
  26. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +1 -1
  27. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +102 -11
  28. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +9 -4
  29. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +4 -1
  30. data/src/core/ext/filters/client_channel/resolver/dns/dns_resolver_plugin.cc +6 -0
  31. data/src/core/ext/filters/client_channel/resolver/dns/event_engine/event_engine_client_channel_resolver.cc +41 -14
  32. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +1 -1
  33. data/src/core/ext/filters/client_channel/resolver/polling_resolver.cc +3 -2
  34. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +1 -1
  35. data/src/core/ext/filters/client_channel/retry_filter.h +1 -0
  36. data/src/core/ext/filters/client_channel/retry_service_config.cc +1 -1
  37. data/src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc +1 -1
  38. data/src/core/ext/filters/client_channel/subchannel.cc +9 -5
  39. data/src/core/ext/filters/client_channel/subchannel.h +8 -2
  40. data/src/core/ext/filters/deadline/deadline_filter.cc +1 -1
  41. data/src/core/ext/filters/http/client/http_client_filter.cc +1 -0
  42. data/src/core/ext/filters/http/client_authority_filter.cc +1 -1
  43. data/src/core/ext/filters/http/message_compress/compression_filter.cc +1 -0
  44. data/src/core/ext/filters/http/server/http_server_filter.cc +1 -1
  45. data/src/core/ext/filters/message_size/message_size_filter.cc +1 -0
  46. data/src/core/ext/filters/rbac/rbac_service_config_parser.cc +4 -7
  47. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +1 -0
  48. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +8 -12
  49. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +357 -358
  50. data/src/core/ext/transport/chttp2/transport/frame_ping.cc +5 -18
  51. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +63 -4
  52. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +7 -2
  53. data/src/core/ext/transport/chttp2/transport/internal.h +30 -57
  54. data/src/core/ext/transport/chttp2/transport/parsing.cc +16 -7
  55. data/src/core/ext/transport/chttp2/transport/ping_abuse_policy.cc +80 -0
  56. data/src/core/ext/transport/chttp2/transport/ping_abuse_policy.h +55 -0
  57. data/src/core/ext/transport/chttp2/transport/ping_rate_policy.cc +98 -0
  58. data/src/core/ext/transport/chttp2/transport/ping_rate_policy.h +73 -0
  59. data/src/core/ext/transport/chttp2/transport/writing.cc +81 -89
  60. data/src/core/ext/transport/inproc/inproc_transport.cc +1 -0
  61. data/src/core/ext/xds/xds_client_grpc.cc +1 -0
  62. data/src/core/ext/xds/xds_http_fault_filter.cc +1 -2
  63. data/src/core/ext/xds/xds_http_fault_filter.h +1 -2
  64. data/src/core/ext/xds/xds_http_filters.h +2 -4
  65. data/src/core/ext/xds/xds_http_rbac_filter.cc +3 -8
  66. data/src/core/ext/xds/xds_http_rbac_filter.h +1 -2
  67. data/src/core/ext/xds/xds_http_stateful_session_filter.cc +1 -2
  68. data/src/core/ext/xds/xds_http_stateful_session_filter.h +1 -2
  69. data/src/core/ext/xds/xds_lb_policy_registry.cc +3 -6
  70. data/src/core/ext/xds/xds_routing.cc +2 -2
  71. data/src/core/ext/xds/xds_transport_grpc.cc +1 -0
  72. data/src/core/lib/avl/avl.h +10 -173
  73. data/src/core/lib/channel/call_tracer.cc +289 -0
  74. data/src/core/lib/channel/call_tracer.h +35 -0
  75. data/src/core/lib/channel/channel_args.cc +84 -79
  76. data/src/core/lib/channel/channel_args.h +29 -17
  77. data/src/core/lib/channel/connected_channel.cc +0 -1
  78. data/src/core/lib/channel/promise_based_filter.cc +4 -1
  79. data/src/core/lib/compression/compression_internal.cc +8 -4
  80. data/src/core/lib/debug/stats_data.cc +93 -21
  81. data/src/core/lib/debug/stats_data.h +41 -0
  82. data/src/core/lib/event_engine/ares_resolver.cc +712 -0
  83. data/src/core/lib/event_engine/ares_resolver.h +150 -0
  84. data/src/core/lib/event_engine/cf_engine/cf_engine.cc +9 -3
  85. data/src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc +2 -2
  86. data/src/core/lib/event_engine/cf_engine/dns_service_resolver.cc +229 -0
  87. data/src/core/lib/event_engine/cf_engine/dns_service_resolver.h +117 -0
  88. data/src/core/lib/event_engine/forkable.cc +15 -1
  89. data/src/core/lib/event_engine/forkable.h +15 -0
  90. data/src/core/lib/event_engine/grpc_polled_fd.h +73 -0
  91. data/src/core/lib/event_engine/posix_engine/ev_poll_posix.cc +25 -3
  92. data/src/core/lib/event_engine/posix_engine/ev_poll_posix.h +10 -1
  93. data/src/core/lib/event_engine/posix_engine/grpc_polled_fd_posix.h +197 -0
  94. data/src/core/lib/event_engine/posix_engine/posix_endpoint.cc +3 -3
  95. data/src/core/lib/event_engine/posix_engine/posix_engine.cc +47 -1
  96. data/src/core/lib/event_engine/posix_engine/posix_engine.h +12 -1
  97. data/src/core/lib/event_engine/posix_engine/tcp_socket_utils.cc +1 -0
  98. data/src/core/lib/event_engine/posix_engine/traced_buffer_list.cc +2 -0
  99. data/src/core/lib/event_engine/thread_pool/thread_count.cc +58 -0
  100. data/src/core/lib/event_engine/thread_pool/thread_count.h +161 -0
  101. data/src/core/lib/event_engine/thread_pool/thread_pool_factory.cc +7 -0
  102. data/src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.cc +86 -111
  103. data/src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.h +15 -61
  104. data/src/core/lib/event_engine/windows/windows_endpoint.cc +3 -4
  105. data/src/core/lib/experiments/config.cc +14 -0
  106. data/src/core/lib/experiments/experiments.cc +141 -304
  107. data/src/core/lib/experiments/experiments.h +16 -17
  108. data/src/core/lib/gprpp/ref_counted.h +3 -1
  109. data/src/core/lib/gprpp/ref_counted_string.cc +44 -0
  110. data/src/core/lib/gprpp/ref_counted_string.h +146 -0
  111. data/src/core/lib/gprpp/time.h +2 -2
  112. data/src/core/lib/gprpp/work_serializer.cc +36 -0
  113. data/src/core/lib/gprpp/work_serializer.h +5 -0
  114. data/src/core/lib/http/httpcli_security_connector.cc +1 -0
  115. data/src/core/lib/iomgr/buffer_list.cc +2 -0
  116. data/src/core/lib/iomgr/event_engine_shims/endpoint.cc +7 -22
  117. data/src/core/lib/iomgr/tcp_posix.cc +3 -3
  118. data/src/core/lib/promise/detail/basic_seq.h +1 -372
  119. data/src/core/lib/promise/detail/seq_state.h +2076 -0
  120. data/src/core/lib/promise/seq.h +19 -2
  121. data/src/core/lib/promise/sleep.h +5 -10
  122. data/src/core/lib/promise/try_seq.h +34 -2
  123. data/src/core/lib/resource_quota/api.cc +1 -0
  124. data/src/core/lib/resource_quota/arena.cc +2 -0
  125. data/src/core/lib/resource_quota/arena.h +42 -8
  126. data/src/core/lib/resource_quota/memory_quota.cc +0 -1
  127. data/src/core/lib/resource_quota/resource_quota.h +1 -0
  128. data/src/core/lib/security/authorization/authorization_policy_provider.h +1 -1
  129. data/src/core/lib/security/authorization/rbac_policy.h +1 -1
  130. data/src/core/lib/security/credentials/external/aws_request_signer.cc +8 -0
  131. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +1 -0
  132. data/src/core/lib/security/credentials/jwt/json_token.cc +17 -0
  133. data/src/core/lib/security/credentials/jwt/json_token.h +4 -0
  134. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +42 -0
  135. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +1 -0
  136. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc +4 -0
  137. data/src/core/lib/security/credentials/tls/tls_credentials.cc +1 -0
  138. data/src/core/lib/security/credentials/xds/xds_credentials.cc +1 -0
  139. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +1 -0
  140. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +1 -0
  141. data/src/core/lib/security/security_connector/ssl_utils.cc +1 -0
  142. data/src/core/lib/security/transport/client_auth_filter.cc +8 -5
  143. data/src/core/lib/security/transport/security_handshaker.cc +1 -0
  144. data/src/core/lib/security/transport/server_auth_filter.cc +2 -0
  145. data/src/core/lib/surface/call.cc +32 -8
  146. data/src/core/lib/surface/channel.cc +1 -0
  147. data/src/core/lib/surface/completion_queue.cc +10 -0
  148. data/src/core/lib/surface/init.cc +1 -0
  149. data/src/core/lib/surface/server.cc +67 -64
  150. data/src/core/lib/surface/server.h +1 -15
  151. data/src/core/lib/surface/version.cc +2 -2
  152. data/src/core/tsi/alts/crypt/aes_gcm.cc +27 -2
  153. data/src/core/tsi/ssl_transport_security.cc +11 -0
  154. data/src/ruby/lib/grpc/generic/active_call.rb +9 -14
  155. data/src/ruby/lib/grpc/version.rb +1 -1
  156. data/src/ruby/pb/test/client.rb +16 -0
  157. data/src/ruby/spec/generic/rpc_server_spec.rb +3 -3
  158. data/third_party/abseil-cpp/absl/algorithm/container.h +3 -2
  159. data/third_party/abseil-cpp/absl/base/attributes.h +58 -5
  160. data/third_party/abseil-cpp/absl/base/call_once.h +1 -1
  161. data/third_party/abseil-cpp/absl/base/casts.h +8 -8
  162. data/third_party/abseil-cpp/absl/base/config.h +89 -106
  163. data/third_party/abseil-cpp/absl/base/dynamic_annotations.h +26 -1
  164. data/third_party/abseil-cpp/absl/base/internal/direct_mmap.h +2 -2
  165. data/third_party/abseil-cpp/absl/base/internal/low_level_alloc.cc +50 -39
  166. data/third_party/abseil-cpp/absl/base/internal/low_level_alloc.h +2 -1
  167. data/third_party/abseil-cpp/absl/base/internal/prefetch.h +17 -18
  168. data/third_party/abseil-cpp/absl/base/internal/raw_logging.cc +32 -3
  169. data/third_party/abseil-cpp/absl/base/internal/raw_logging.h +24 -4
  170. data/third_party/abseil-cpp/absl/base/internal/sysinfo.cc +31 -73
  171. data/third_party/abseil-cpp/absl/base/internal/thread_identity.cc +9 -8
  172. data/third_party/abseil-cpp/absl/base/internal/thread_identity.h +11 -11
  173. data/third_party/abseil-cpp/absl/base/internal/throw_delegate.cc +23 -32
  174. data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.cc +2 -3
  175. data/third_party/abseil-cpp/absl/base/options.h +1 -1
  176. data/third_party/abseil-cpp/absl/base/policy_checks.h +3 -3
  177. data/third_party/abseil-cpp/absl/base/prefetch.h +198 -0
  178. data/third_party/abseil-cpp/absl/container/fixed_array.h +54 -29
  179. data/third_party/abseil-cpp/absl/container/flat_hash_map.h +5 -1
  180. data/third_party/abseil-cpp/absl/container/flat_hash_set.h +6 -2
  181. data/third_party/abseil-cpp/absl/container/inlined_vector.h +167 -79
  182. data/third_party/abseil-cpp/absl/container/internal/common_policy_traits.h +1 -1
  183. data/third_party/abseil-cpp/absl/container/internal/compressed_tuple.h +3 -21
  184. data/third_party/abseil-cpp/absl/container/internal/container_memory.h +1 -1
  185. data/third_party/abseil-cpp/absl/container/internal/hash_function_defaults.h +46 -0
  186. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.cc +2 -0
  187. data/third_party/abseil-cpp/absl/container/internal/inlined_vector.h +85 -26
  188. data/third_party/abseil-cpp/absl/container/internal/raw_hash_map.h +35 -18
  189. data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.cc +70 -29
  190. data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.h +437 -236
  191. data/third_party/abseil-cpp/absl/crc/crc32c.h +8 -1
  192. data/third_party/abseil-cpp/absl/crc/internal/cpu_detect.cc +14 -8
  193. data/third_party/abseil-cpp/absl/crc/internal/crc.cc +4 -35
  194. data/third_party/abseil-cpp/absl/crc/internal/crc.h +2 -10
  195. data/third_party/abseil-cpp/absl/crc/internal/crc32_x86_arm_combined_simd.h +1 -1
  196. data/third_party/abseil-cpp/absl/crc/internal/crc_cord_state.cc +1 -1
  197. data/third_party/abseil-cpp/absl/crc/internal/crc_cord_state.h +4 -4
  198. data/third_party/abseil-cpp/absl/crc/internal/crc_internal.h +8 -10
  199. data/third_party/abseil-cpp/absl/crc/internal/crc_memcpy_x86_64.cc +17 -19
  200. data/third_party/abseil-cpp/absl/crc/internal/crc_x86_arm_combined.cc +8 -8
  201. data/third_party/abseil-cpp/absl/debugging/internal/elf_mem_image.h +2 -1
  202. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_aarch64-inl.inc +59 -23
  203. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_powerpc-inl.inc +1 -1
  204. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_x86-inl.inc +1 -1
  205. data/third_party/abseil-cpp/absl/debugging/internal/symbolize.h +1 -1
  206. data/third_party/abseil-cpp/absl/debugging/symbolize_elf.inc +43 -19
  207. data/third_party/abseil-cpp/absl/debugging/symbolize_emscripten.inc +3 -0
  208. data/third_party/abseil-cpp/absl/flags/commandlineflag.h +1 -1
  209. data/third_party/abseil-cpp/absl/flags/internal/commandlineflag.cc +1 -1
  210. data/third_party/abseil-cpp/absl/flags/internal/flag.cc +2 -2
  211. data/third_party/abseil-cpp/absl/flags/internal/flag.h +16 -15
  212. data/third_party/abseil-cpp/absl/flags/internal/flag_msvc.inc +1 -1
  213. data/third_party/abseil-cpp/absl/flags/marshalling.cc +43 -2
  214. data/third_party/abseil-cpp/absl/flags/marshalling.h +5 -0
  215. data/third_party/abseil-cpp/absl/functional/any_invocable.h +9 -1
  216. data/third_party/abseil-cpp/absl/functional/bind_front.h +1 -1
  217. data/third_party/abseil-cpp/absl/functional/function_ref.h +3 -3
  218. data/third_party/abseil-cpp/absl/functional/internal/any_invocable.h +37 -24
  219. data/third_party/abseil-cpp/absl/functional/internal/function_ref.h +19 -9
  220. data/third_party/abseil-cpp/absl/hash/hash.h +7 -4
  221. data/third_party/abseil-cpp/absl/hash/internal/hash.h +38 -15
  222. data/third_party/abseil-cpp/absl/hash/internal/low_level_hash.cc +6 -0
  223. data/third_party/abseil-cpp/absl/meta/type_traits.h +48 -373
  224. data/third_party/abseil-cpp/absl/numeric/bits.h +4 -4
  225. data/third_party/abseil-cpp/absl/numeric/int128.cc +20 -8
  226. data/third_party/abseil-cpp/absl/numeric/int128.h +36 -39
  227. data/third_party/abseil-cpp/absl/numeric/int128_have_intrinsic.inc +0 -3
  228. data/third_party/abseil-cpp/absl/numeric/int128_no_intrinsic.inc +47 -30
  229. data/third_party/abseil-cpp/absl/random/internal/fast_uniform_bits.h +4 -3
  230. data/third_party/abseil-cpp/absl/random/internal/generate_real.h +1 -1
  231. data/third_party/abseil-cpp/absl/random/internal/platform.h +1 -1
  232. data/third_party/abseil-cpp/absl/random/internal/randen_detect.cc +4 -0
  233. data/third_party/abseil-cpp/absl/random/internal/randen_engine.h +1 -1
  234. data/third_party/abseil-cpp/absl/random/internal/randen_hwaes.cc +1 -1
  235. data/third_party/abseil-cpp/absl/random/internal/uniform_helper.h +1 -1
  236. data/third_party/abseil-cpp/absl/status/internal/status_internal.h +4 -0
  237. data/third_party/abseil-cpp/absl/status/internal/statusor_internal.h +12 -24
  238. data/third_party/abseil-cpp/absl/status/status.cc +11 -7
  239. data/third_party/abseil-cpp/absl/status/status.h +11 -2
  240. data/third_party/abseil-cpp/absl/status/statusor.h +22 -8
  241. data/third_party/abseil-cpp/absl/strings/ascii.cc +54 -6
  242. data/third_party/abseil-cpp/absl/strings/charconv.cc +21 -4
  243. data/third_party/abseil-cpp/absl/strings/charconv.h +2 -2
  244. data/third_party/abseil-cpp/absl/strings/cord.cc +1 -2
  245. data/third_party/abseil-cpp/absl/strings/cord.h +32 -5
  246. data/third_party/abseil-cpp/absl/strings/cord_analysis.cc +23 -1
  247. data/third_party/abseil-cpp/absl/strings/cord_analysis.h +18 -0
  248. data/third_party/abseil-cpp/absl/strings/cord_buffer.h +2 -5
  249. data/third_party/abseil-cpp/absl/strings/escaping.cc +10 -32
  250. data/third_party/abseil-cpp/absl/strings/escaping.h +1 -1
  251. data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.cc +2 -4
  252. data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.h +3 -3
  253. data/third_party/abseil-cpp/absl/strings/internal/cord_internal.cc +0 -1
  254. data/third_party/abseil-cpp/absl/strings/internal/cord_internal.h +15 -13
  255. data/third_party/abseil-cpp/absl/strings/internal/cord_rep_btree.cc +13 -4
  256. data/third_party/abseil-cpp/absl/strings/internal/cord_rep_btree.h +8 -0
  257. data/third_party/abseil-cpp/absl/strings/internal/cord_rep_consume.cc +5 -3
  258. data/third_party/abseil-cpp/absl/strings/internal/cord_rep_consume.h +4 -7
  259. data/third_party/abseil-cpp/absl/strings/internal/cord_rep_flat.h +8 -0
  260. data/third_party/abseil-cpp/absl/strings/internal/cord_rep_ring.h +2 -2
  261. data/third_party/abseil-cpp/absl/strings/internal/cordz_handle.cc +46 -20
  262. data/third_party/abseil-cpp/absl/strings/internal/cordz_handle.h +1 -34
  263. data/third_party/abseil-cpp/absl/strings/internal/cordz_info.cc +2 -1
  264. data/third_party/abseil-cpp/absl/strings/internal/escaping.cc +23 -0
  265. data/third_party/abseil-cpp/absl/strings/internal/escaping.h +1 -0
  266. data/third_party/abseil-cpp/absl/strings/internal/memutil.cc +2 -77
  267. data/third_party/abseil-cpp/absl/strings/internal/memutil.h +4 -112
  268. data/third_party/abseil-cpp/absl/strings/internal/stl_type_traits.h +1 -1
  269. data/third_party/abseil-cpp/absl/strings/internal/str_format/arg.cc +10 -31
  270. data/third_party/abseil-cpp/absl/strings/internal/str_format/arg.h +8 -8
  271. data/third_party/abseil-cpp/absl/strings/internal/str_format/bind.h +5 -20
  272. data/third_party/abseil-cpp/absl/strings/internal/str_format/constexpr_parser.h +1 -0
  273. data/third_party/abseil-cpp/absl/strings/internal/str_format/extension.h +1 -1
  274. data/third_party/abseil-cpp/absl/strings/internal/str_format/float_conversion.cc +9 -9
  275. data/third_party/abseil-cpp/absl/strings/internal/str_split_internal.h +56 -6
  276. data/third_party/abseil-cpp/absl/strings/match.cc +87 -0
  277. data/third_party/abseil-cpp/absl/strings/match.h +19 -0
  278. data/third_party/abseil-cpp/absl/strings/numbers.cc +154 -122
  279. data/third_party/abseil-cpp/absl/strings/numbers.h +1 -6
  280. data/third_party/abseil-cpp/absl/strings/str_cat.cc +7 -50
  281. data/third_party/abseil-cpp/absl/strings/str_cat.h +83 -15
  282. data/third_party/abseil-cpp/absl/strings/str_format.h +6 -3
  283. data/third_party/abseil-cpp/absl/strings/str_split.cc +9 -6
  284. data/third_party/abseil-cpp/absl/strings/string_view.cc +26 -4
  285. data/third_party/abseil-cpp/absl/synchronization/internal/create_thread_identity.cc +5 -0
  286. data/third_party/abseil-cpp/absl/synchronization/internal/futex.h +63 -43
  287. data/third_party/abseil-cpp/absl/synchronization/internal/futex_waiter.cc +111 -0
  288. data/third_party/abseil-cpp/absl/synchronization/internal/futex_waiter.h +63 -0
  289. data/third_party/abseil-cpp/absl/synchronization/internal/graphcycles.cc +11 -7
  290. data/third_party/abseil-cpp/absl/synchronization/internal/kernel_timeout.cc +225 -0
  291. data/third_party/abseil-cpp/absl/synchronization/internal/kernel_timeout.h +122 -114
  292. data/third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.cc +12 -8
  293. data/third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.h +10 -1
  294. data/third_party/abseil-cpp/absl/synchronization/internal/pthread_waiter.cc +167 -0
  295. data/third_party/abseil-cpp/absl/synchronization/internal/pthread_waiter.h +60 -0
  296. data/third_party/abseil-cpp/absl/synchronization/internal/sem_waiter.cc +122 -0
  297. data/third_party/abseil-cpp/absl/synchronization/internal/sem_waiter.h +65 -0
  298. data/third_party/abseil-cpp/absl/synchronization/internal/stdcpp_waiter.cc +91 -0
  299. data/third_party/abseil-cpp/absl/synchronization/internal/stdcpp_waiter.h +56 -0
  300. data/third_party/abseil-cpp/absl/synchronization/internal/waiter.h +19 -113
  301. data/third_party/abseil-cpp/absl/synchronization/internal/waiter_base.cc +42 -0
  302. data/third_party/abseil-cpp/absl/synchronization/internal/waiter_base.h +90 -0
  303. data/third_party/abseil-cpp/absl/synchronization/internal/win32_waiter.cc +151 -0
  304. data/third_party/abseil-cpp/absl/synchronization/internal/win32_waiter.h +70 -0
  305. data/third_party/abseil-cpp/absl/synchronization/mutex.cc +407 -411
  306. data/third_party/abseil-cpp/absl/synchronization/mutex.h +152 -118
  307. data/third_party/abseil-cpp/absl/time/clock.cc +6 -7
  308. data/third_party/abseil-cpp/absl/time/duration.cc +24 -26
  309. data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/time_zone.h +1 -0
  310. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_fixed.cc +1 -1
  311. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_format.cc +3 -3
  312. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_if.cc +8 -6
  313. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_if.h +6 -3
  314. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_impl.cc +4 -2
  315. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_impl.h +4 -0
  316. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_info.cc +322 -295
  317. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_info.h +8 -17
  318. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_libc.cc +51 -33
  319. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_libc.h +7 -2
  320. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_lookup.cc +128 -2
  321. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_posix.h +1 -1
  322. data/third_party/abseil-cpp/absl/time/internal/cctz/src/tzfile.h +5 -1
  323. data/third_party/abseil-cpp/absl/time/internal/cctz/src/zone_info_source.cc +34 -34
  324. data/third_party/abseil-cpp/absl/time/time.cc +9 -2
  325. data/third_party/abseil-cpp/absl/time/time.h +115 -15
  326. data/third_party/abseil-cpp/absl/types/internal/optional.h +0 -52
  327. data/third_party/abseil-cpp/absl/types/internal/span.h +2 -2
  328. data/third_party/abseil-cpp/absl/types/internal/variant.h +2 -2
  329. data/third_party/abseil-cpp/absl/types/optional.h +15 -13
  330. data/third_party/abseil-cpp/absl/types/span.h +1 -2
  331. data/third_party/boringssl-with-bazel/err_data.c +15 -14
  332. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_gentm.c +7 -3
  333. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_strex.c +7 -7
  334. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_utctm.c +7 -3
  335. data/third_party/boringssl-with-bazel/src/crypto/bio/connect.c +5 -5
  336. data/third_party/boringssl-with-bazel/src/crypto/bio/errno.c +92 -0
  337. data/third_party/boringssl-with-bazel/src/crypto/bio/fd.c +4 -48
  338. data/third_party/boringssl-with-bazel/src/crypto/bio/file.c +11 -6
  339. data/third_party/boringssl-with-bazel/src/crypto/bio/internal.h +16 -6
  340. data/third_party/boringssl-with-bazel/src/crypto/bio/socket.c +2 -2
  341. data/third_party/boringssl-with-bazel/src/crypto/bio/socket_helper.c +9 -0
  342. data/third_party/boringssl-with-bazel/src/crypto/bytestring/cbs.c +1 -1
  343. data/third_party/boringssl-with-bazel/src/crypto/conf/conf.c +3 -7
  344. data/third_party/boringssl-with-bazel/src/crypto/cpu_aarch64_apple.c +0 -2
  345. data/third_party/boringssl-with-bazel/src/crypto/cpu_aarch64_fuchsia.c +0 -1
  346. data/third_party/boringssl-with-bazel/src/crypto/cpu_aarch64_linux.c +0 -2
  347. data/third_party/boringssl-with-bazel/src/crypto/cpu_aarch64_openbsd.c +0 -1
  348. data/third_party/boringssl-with-bazel/src/crypto/cpu_aarch64_sysreg.c +93 -0
  349. data/third_party/boringssl-with-bazel/src/crypto/cpu_aarch64_win.c +1 -1
  350. data/third_party/boringssl-with-bazel/src/crypto/cpu_arm_freebsd.c +0 -1
  351. data/third_party/boringssl-with-bazel/src/crypto/cpu_arm_linux.c +0 -2
  352. data/third_party/boringssl-with-bazel/src/crypto/dh_extra/dh_asn1.c +4 -0
  353. data/third_party/boringssl-with-bazel/src/crypto/dh_extra/params.c +5 -0
  354. data/third_party/boringssl-with-bazel/src/crypto/ec_extra/hash_to_curve.c +9 -14
  355. data/third_party/boringssl-with-bazel/src/crypto/ec_extra/internal.h +4 -6
  356. data/third_party/boringssl-with-bazel/src/crypto/err/err.c +10 -11
  357. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/dh/check.c +37 -8
  358. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/dh/dh.c +38 -19
  359. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/dh/internal.h +7 -0
  360. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/self_check/self_check.c +39 -16
  361. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/service_indicator/service_indicator.c +4 -7
  362. data/third_party/boringssl-with-bazel/src/crypto/hpke/hpke.c +7 -0
  363. data/third_party/boringssl-with-bazel/src/crypto/internal.h +13 -21
  364. data/third_party/boringssl-with-bazel/src/crypto/obj/obj.c +6 -23
  365. data/third_party/boringssl-with-bazel/src/crypto/rand_extra/getentropy.c +4 -0
  366. data/third_party/boringssl-with-bazel/src/crypto/stack/stack.c +5 -0
  367. data/third_party/boringssl-with-bazel/src/crypto/x509/by_dir.c +1 -6
  368. data/third_party/boringssl-with-bazel/src/crypto/x509/by_file.c +0 -3
  369. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_d2.c +1 -3
  370. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_alt.c +2 -3
  371. data/third_party/boringssl-with-bazel/src/include/openssl/base.h +9 -1
  372. data/third_party/boringssl-with-bazel/src/include/openssl/bio.h +11 -1
  373. data/third_party/boringssl-with-bazel/src/include/openssl/dh.h +4 -1
  374. data/third_party/boringssl-with-bazel/src/include/openssl/ec.h +7 -9
  375. data/third_party/boringssl-with-bazel/src/include/openssl/hpke.h +6 -2
  376. data/third_party/boringssl-with-bazel/src/include/openssl/span.h +22 -20
  377. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +4 -0
  378. data/third_party/boringssl-with-bazel/src/include/openssl/stack.h +20 -12
  379. data/third_party/boringssl-with-bazel/src/include/openssl/target.h +50 -3
  380. data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +0 -4
  381. data/third_party/boringssl-with-bazel/src/ssl/ssl_cipher.cc +2 -2
  382. data/third_party/boringssl-with-bazel/src/ssl/ssl_file.cc +4 -4
  383. data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +2 -0
  384. metadata +41 -33
  385. data/src/core/lib/promise/detail/basic_join.h +0 -197
  386. data/src/core/lib/promise/detail/switch.h +0 -1455
  387. data/src/core/lib/promise/try_join.h +0 -82
  388. data/third_party/abseil-cpp/absl/synchronization/internal/waiter.cc +0 -403
  389. data/third_party/boringssl-with-bazel/src/crypto/cpu_aarch64_freebsd.c +0 -62
  390. data/third_party/boringssl-with-bazel/src/crypto/cpu_arm.c +0 -38
  391. data/third_party/boringssl-with-bazel/src/crypto/cpu_arm_openbsd.c +0 -31
  392. data/third_party/re2/util/benchmark.h +0 -156
  393. data/third_party/re2/util/flags.h +0 -26
  394. data/third_party/re2/util/malloc_counter.h +0 -19
  395. data/third_party/re2/util/pcre.cc +0 -1025
  396. data/third_party/re2/util/pcre.h +0 -681
  397. data/third_party/re2/util/test.h +0 -50
  398. data/third_party/upb/upb/mini_table.h +0 -36
  399. data/third_party/zlib/gzclose.c +0 -25
  400. data/third_party/zlib/gzlib.c +0 -639
  401. data/third_party/zlib/gzread.c +0 -650
  402. data/third_party/zlib/gzwrite.c +0 -677
@@ -28,6 +28,7 @@
28
28
  #include <memory>
29
29
  #include <new>
30
30
  #include <string>
31
+ #include <type_traits>
31
32
  #include <utility>
32
33
  #include <vector>
33
34
 
@@ -44,6 +45,7 @@
44
45
 
45
46
  #include <grpc/event_engine/event_engine.h>
46
47
  #include <grpc/grpc.h>
48
+ #include <grpc/impl/channel_arg_names.h>
47
49
  #include <grpc/impl/connectivity_state.h>
48
50
  #include <grpc/slice_buffer.h>
49
51
  #include <grpc/status.h>
@@ -61,6 +63,8 @@
61
63
  #include "src/core/ext/transport/chttp2/transport/http2_settings.h"
62
64
  #include "src/core/ext/transport/chttp2/transport/http_trace.h"
63
65
  #include "src/core/ext/transport/chttp2/transport/internal.h"
66
+ #include "src/core/ext/transport/chttp2/transport/ping_abuse_policy.h"
67
+ #include "src/core/ext/transport/chttp2/transport/ping_rate_policy.h"
64
68
  #include "src/core/ext/transport/chttp2/transport/varint.h"
65
69
  #include "src/core/lib/channel/call_tracer.h"
66
70
  #include "src/core/lib/channel/channel_args.h"
@@ -123,25 +127,26 @@ static grpc_core::Duration g_default_server_keepalive_timeout =
123
127
  static bool g_default_client_keepalive_permit_without_calls = false;
124
128
  static bool g_default_server_keepalive_permit_without_calls = false;
125
129
 
126
- static grpc_core::Duration g_default_min_recv_ping_interval_without_data =
127
- grpc_core::Duration::Minutes(5);
128
- static int g_default_max_pings_without_data = 2;
129
- static int g_default_max_ping_strikes = 2;
130
-
131
130
  #define MAX_CLIENT_STREAM_ID 0x7fffffffu
132
131
  grpc_core::TraceFlag grpc_keepalive_trace(false, "http_keepalive");
133
132
  grpc_core::DebugOnlyTraceFlag grpc_trace_chttp2_refcount(false,
134
133
  "chttp2_refcount");
135
134
 
136
135
  // forward declarations of various callbacks that we'll build closures around
137
- static void write_action_begin_locked(void* t, grpc_error_handle error);
138
- static void write_action(void* t, grpc_error_handle error);
139
- static void write_action_end(void* t, grpc_error_handle error);
140
- static void write_action_end_locked(void* t, grpc_error_handle error);
141
-
142
- static void read_action(void* t, grpc_error_handle error);
143
- static void read_action_locked(void* t, grpc_error_handle error);
144
- static void continue_read_action_locked(grpc_chttp2_transport* t);
136
+ static void write_action_begin_locked(
137
+ grpc_core::RefCountedPtr<grpc_chttp2_transport>, grpc_error_handle error);
138
+ static void write_action(grpc_chttp2_transport* t);
139
+ static void write_action_end(grpc_core::RefCountedPtr<grpc_chttp2_transport>,
140
+ grpc_error_handle error);
141
+ static void write_action_end_locked(
142
+ grpc_core::RefCountedPtr<grpc_chttp2_transport>, grpc_error_handle error);
143
+
144
+ static void read_action(grpc_core::RefCountedPtr<grpc_chttp2_transport>,
145
+ grpc_error_handle error);
146
+ static void read_action_locked(grpc_core::RefCountedPtr<grpc_chttp2_transport>,
147
+ grpc_error_handle error);
148
+ static void continue_read_action_locked(
149
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t);
145
150
 
146
151
  // Set a transport level setting, and push it to our peer
147
152
  static void queue_setting_update(grpc_chttp2_transport* t,
@@ -158,8 +163,10 @@ static void connectivity_state_set(grpc_chttp2_transport* t,
158
163
  const absl::Status& status,
159
164
  const char* reason);
160
165
 
161
- static void benign_reclaimer_locked(void* arg, grpc_error_handle error);
162
- static void destructive_reclaimer_locked(void* arg, grpc_error_handle error);
166
+ static void benign_reclaimer_locked(
167
+ grpc_core::RefCountedPtr<grpc_chttp2_transport>, grpc_error_handle error);
168
+ static void destructive_reclaimer_locked(
169
+ grpc_core::RefCountedPtr<grpc_chttp2_transport>, grpc_error_handle error);
163
170
 
164
171
  static void post_benign_reclaimer(grpc_chttp2_transport* t);
165
172
  static void post_destructive_reclaimer(grpc_chttp2_transport* t);
@@ -169,31 +176,45 @@ static void close_transport_locked(grpc_chttp2_transport* t,
169
176
  static void end_all_the_calls(grpc_chttp2_transport* t,
170
177
  grpc_error_handle error);
171
178
 
172
- static void start_bdp_ping(void* tp, grpc_error_handle error);
173
- static void finish_bdp_ping(void* tp, grpc_error_handle error);
174
- static void start_bdp_ping_locked(void* tp, grpc_error_handle error);
175
- static void finish_bdp_ping_locked(void* tp, grpc_error_handle error);
179
+ static void start_bdp_ping(grpc_core::RefCountedPtr<grpc_chttp2_transport>,
180
+ grpc_error_handle error);
181
+ static void finish_bdp_ping(grpc_core::RefCountedPtr<grpc_chttp2_transport>,
182
+ grpc_error_handle error);
183
+ static void start_bdp_ping_locked(
184
+ grpc_core::RefCountedPtr<grpc_chttp2_transport>, grpc_error_handle error);
185
+ static void finish_bdp_ping_locked(
186
+ grpc_core::RefCountedPtr<grpc_chttp2_transport>, grpc_error_handle error);
176
187
  static void next_bdp_ping_timer_expired(grpc_chttp2_transport* t);
177
188
  static void next_bdp_ping_timer_expired_locked(
178
- void* tp, GRPC_UNUSED grpc_error_handle error);
189
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> tp,
190
+ GRPC_UNUSED grpc_error_handle error);
179
191
 
180
192
  static void cancel_pings(grpc_chttp2_transport* t, grpc_error_handle error);
181
193
  static void send_ping_locked(grpc_chttp2_transport* t,
182
194
  grpc_closure* on_initiate, grpc_closure* on_ack);
183
- static void retry_initiate_ping_locked(void* tp,
184
- GRPC_UNUSED grpc_error_handle error);
195
+ static void retry_initiate_ping_locked(
196
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t,
197
+ GRPC_UNUSED grpc_error_handle error);
185
198
 
186
199
  // keepalive-relevant functions
187
- static void init_keepalive_ping(grpc_chttp2_transport* t);
188
- static void init_keepalive_ping_locked(void* arg,
189
- GRPC_UNUSED grpc_error_handle error);
190
- static void start_keepalive_ping(void* arg, grpc_error_handle error);
191
- static void finish_keepalive_ping(void* arg, grpc_error_handle error);
192
- static void start_keepalive_ping_locked(void* arg, grpc_error_handle error);
193
- static void finish_keepalive_ping_locked(void* arg, grpc_error_handle error);
194
- static void keepalive_watchdog_fired(grpc_chttp2_transport* t);
200
+ static void init_keepalive_ping(
201
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t);
202
+ static void init_keepalive_ping_locked(
203
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t,
204
+ GRPC_UNUSED grpc_error_handle error);
205
+ static void start_keepalive_ping(
206
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t, grpc_error_handle error);
207
+ static void finish_keepalive_ping(
208
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t, grpc_error_handle error);
209
+ static void start_keepalive_ping_locked(
210
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t, grpc_error_handle error);
211
+ static void finish_keepalive_ping_locked(
212
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t, grpc_error_handle error);
213
+ static void keepalive_watchdog_fired(
214
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t);
195
215
  static void keepalive_watchdog_fired_locked(
196
- void* arg, GRPC_UNUSED grpc_error_handle error);
216
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t,
217
+ GRPC_UNUSED grpc_error_handle error);
197
218
  static void maybe_reset_keepalive_ping_timer_locked(grpc_chttp2_transport* t);
198
219
 
199
220
  namespace {
@@ -213,6 +234,24 @@ grpc_core::CopyContextFn g_get_copied_context_fn = nullptr;
213
234
 
214
235
  namespace grpc_core {
215
236
 
237
+ namespace {
238
+ // Initialize a grpc_closure \a c to call \a Fn with \a t and \a error. Holds
239
+ // the passed in reference to \a t until it's moved into Fn.
240
+ template <void (*Fn)(RefCountedPtr<grpc_chttp2_transport>, grpc_error_handle)>
241
+ grpc_closure* InitTransportClosure(RefCountedPtr<grpc_chttp2_transport> t,
242
+ grpc_closure* c) {
243
+ GRPC_CLOSURE_INIT(
244
+ c,
245
+ [](void* tp, grpc_error_handle error) {
246
+ Fn(RefCountedPtr<grpc_chttp2_transport>(
247
+ static_cast<grpc_chttp2_transport*>(tp)),
248
+ std::move(error));
249
+ },
250
+ t.release(), nullptr);
251
+ return c;
252
+ }
253
+ } // namespace
254
+
216
255
  namespace {
217
256
  TestOnlyGlobalHttp2TransportInitCallback test_only_init_callback = nullptr;
218
257
  TestOnlyGlobalHttp2TransportDestructCallback test_only_destruct_callback =
@@ -346,18 +385,6 @@ static void read_channel_args(grpc_chttp2_transport* t,
346
385
  t->hpack_compressor.SetMaxUsableSize(max_hpack_table_size);
347
386
  }
348
387
 
349
- t->ping_policy.max_pings_without_data =
350
- std::max(0, channel_args.GetInt(GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA)
351
- .value_or(g_default_max_pings_without_data));
352
- t->ping_policy.max_ping_strikes =
353
- std::max(0, channel_args.GetInt(GRPC_ARG_HTTP2_MAX_PING_STRIKES)
354
- .value_or(g_default_max_ping_strikes));
355
- t->ping_policy.min_recv_ping_interval_without_data =
356
- std::max(grpc_core::Duration::Zero(),
357
- channel_args
358
- .GetDurationFromIntMillis(
359
- GRPC_ARG_HTTP2_MIN_RECV_PING_INTERVAL_WITHOUT_DATA_MS)
360
- .value_or(g_default_min_recv_ping_interval_without_data));
361
388
  t->write_buffer_size =
362
389
  std::max(0, channel_args.GetInt(GRPC_ARG_HTTP2_WRITE_BUFFER_SIZE)
363
390
  .value_or(grpc_core::chttp2::kDefaultWindow));
@@ -371,16 +398,18 @@ static void read_channel_args(grpc_chttp2_transport* t,
371
398
  channel_args.GetDurationFromIntMillis(GRPC_ARG_KEEPALIVE_TIMEOUT_MS)
372
399
  .value_or(t->is_client ? g_default_client_keepalive_timeout
373
400
  : g_default_server_keepalive_timeout));
374
- if (grpc_core::IsKeepaliveFixEnabled()) {
401
+ if (t->is_client) {
375
402
  t->keepalive_permit_without_calls =
376
403
  channel_args.GetBool(GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS)
377
- .value_or(t->is_client
404
+ .value_or(grpc_core::IsKeepaliveFixEnabled()
378
405
  ? g_default_client_keepalive_permit_without_calls
379
- : g_default_server_keepalive_permit_without_calls);
406
+ : false);
380
407
  } else {
381
408
  t->keepalive_permit_without_calls =
382
409
  channel_args.GetBool(GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS)
383
- .value_or(false);
410
+ .value_or(grpc_core::IsKeepaliveServerFixEnabled()
411
+ ? g_default_server_keepalive_permit_without_calls
412
+ : false);
384
413
  }
385
414
 
386
415
  // Only send the prefered rx frame size http2 setting if we are instructed
@@ -507,17 +536,16 @@ static void read_channel_args(grpc_chttp2_transport* t,
507
536
  }
508
537
 
509
538
  static void init_keepalive_pings_if_enabled_locked(
510
- void* arg, GRPC_UNUSED grpc_error_handle error) {
539
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t,
540
+ GRPC_UNUSED grpc_error_handle error) {
511
541
  GPR_DEBUG_ASSERT(error.ok());
512
- grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(arg);
513
542
  if (t->keepalive_time != grpc_core::Duration::Infinity()) {
514
543
  t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_WAITING;
515
- GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping");
516
544
  t->keepalive_ping_timer_handle =
517
- t->event_engine->RunAfter(t->keepalive_time, [t] {
545
+ t->event_engine->RunAfter(t->keepalive_time, [t = t->Ref()]() mutable {
518
546
  grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
519
547
  grpc_core::ExecCtx exec_ctx;
520
- init_keepalive_ping(t);
548
+ init_keepalive_ping(std::move(t));
521
549
  });
522
550
  } else {
523
551
  // Use GRPC_CHTTP2_KEEPALIVE_STATE_DISABLED to indicate there are no
@@ -546,6 +574,8 @@ grpc_chttp2_transport::grpc_chttp2_transport(
546
574
  GRPC_CHANNEL_READY),
547
575
  is_client(is_client),
548
576
  next_stream_id(is_client ? 1 : 2),
577
+ ping_abuse_policy(channel_args),
578
+ ping_rate_policy(channel_args, is_client),
549
579
  flow_control(
550
580
  peer_string.as_string_view(),
551
581
  channel_args.GetBool(GRPC_ARG_HTTP2_BDP_PROBE).value_or(true),
@@ -588,17 +618,10 @@ grpc_chttp2_transport::grpc_chttp2_transport(
588
618
 
589
619
  read_channel_args(this, channel_args, is_client);
590
620
 
591
- // No pings allowed before receiving a header or data frame.
592
- ping_state.pings_before_data_required = 0;
593
- ping_state.last_ping_sent_time = grpc_core::Timestamp::InfPast();
594
-
595
- ping_recv_state.last_ping_recv_time = grpc_core::Timestamp::InfPast();
596
- ping_recv_state.ping_strikes = 0;
597
-
598
621
  grpc_core::ExecCtx exec_ctx;
599
622
  combiner->Run(
600
- GRPC_CLOSURE_INIT(&init_keepalive_ping_locked,
601
- init_keepalive_pings_if_enabled_locked, this, nullptr),
623
+ grpc_core::InitTransportClosure<init_keepalive_pings_if_enabled_locked>(
624
+ Ref(), &init_keepalive_ping_locked),
602
625
  absl::OkStatus());
603
626
 
604
627
  if (flow_control.bdp_probe()) {
@@ -623,15 +646,15 @@ grpc_chttp2_transport::grpc_chttp2_transport(
623
646
  }
624
647
 
625
648
  static void destroy_transport_locked(void* tp, grpc_error_handle /*error*/) {
626
- grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(tp);
649
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t(
650
+ static_cast<grpc_chttp2_transport*>(tp));
627
651
  t->destroying = 1;
628
652
  close_transport_locked(
629
- t, grpc_error_set_int(GRPC_ERROR_CREATE("Transport destroyed"),
630
- grpc_core::StatusIntProperty::kOccurredDuringWrite,
631
- t->write_state));
653
+ t.get(),
654
+ grpc_error_set_int(GRPC_ERROR_CREATE("Transport destroyed"),
655
+ grpc_core::StatusIntProperty::kOccurredDuringWrite,
656
+ t->write_state));
632
657
  t->memory_owner.Reset();
633
- // Must be the last line.
634
- GRPC_CHTTP2_UNREF_TRANSPORT(t, "destroy");
635
658
  }
636
659
 
637
660
  static void destroy_transport(grpc_transport* gt) {
@@ -663,15 +686,13 @@ static void close_transport_locked(grpc_chttp2_transport* t,
663
686
  t->closed_with_error = error;
664
687
  connectivity_state_set(t, GRPC_CHANNEL_SHUTDOWN, absl::Status(),
665
688
  "close_transport");
666
- if (t->ping_state.delayed_ping_timer_handle.has_value()) {
667
- if (t->event_engine->Cancel(*t->ping_state.delayed_ping_timer_handle)) {
668
- GRPC_CHTTP2_UNREF_TRANSPORT(t, "retry_initiate_ping_locked");
669
- t->ping_state.delayed_ping_timer_handle.reset();
689
+ if (t->delayed_ping_timer_handle.has_value()) {
690
+ if (t->event_engine->Cancel(*t->delayed_ping_timer_handle)) {
691
+ t->delayed_ping_timer_handle.reset();
670
692
  }
671
693
  }
672
694
  if (t->next_bdp_ping_timer_handle.has_value()) {
673
695
  if (t->event_engine->Cancel(*t->next_bdp_ping_timer_handle)) {
674
- GRPC_CHTTP2_UNREF_TRANSPORT(t, "bdp_ping");
675
696
  t->next_bdp_ping_timer_handle.reset();
676
697
  }
677
698
  }
@@ -679,7 +700,6 @@ static void close_transport_locked(grpc_chttp2_transport* t,
679
700
  case GRPC_CHTTP2_KEEPALIVE_STATE_WAITING:
680
701
  if (t->keepalive_ping_timer_handle.has_value()) {
681
702
  if (t->event_engine->Cancel(*t->keepalive_ping_timer_handle)) {
682
- GRPC_CHTTP2_UNREF_TRANSPORT(t, "init keepalive ping");
683
703
  t->keepalive_ping_timer_handle.reset();
684
704
  }
685
705
  }
@@ -687,13 +707,11 @@ static void close_transport_locked(grpc_chttp2_transport* t,
687
707
  case GRPC_CHTTP2_KEEPALIVE_STATE_PINGING:
688
708
  if (t->keepalive_ping_timer_handle.has_value()) {
689
709
  if (t->event_engine->Cancel(*t->keepalive_ping_timer_handle)) {
690
- GRPC_CHTTP2_UNREF_TRANSPORT(t, "init keepalive ping");
691
710
  t->keepalive_ping_timer_handle.reset();
692
711
  }
693
712
  }
694
713
  if (t->keepalive_watchdog_timer_handle.has_value()) {
695
714
  if (t->event_engine->Cancel(*t->keepalive_watchdog_timer_handle)) {
696
- GRPC_CHTTP2_UNREF_TRANSPORT(t, "keepalive watchdog");
697
715
  t->keepalive_watchdog_timer_handle.reset();
698
716
  }
699
717
  }
@@ -739,21 +757,23 @@ void grpc_chttp2_stream_unref(grpc_chttp2_stream* s) {
739
757
  }
740
758
  #endif
741
759
 
742
- grpc_chttp2_stream::Reffer::Reffer(grpc_chttp2_stream* s) {
743
- // We reserve one 'active stream' that's dropped when the stream is
744
- // read-closed. The others are for Chttp2IncomingByteStreams that are
745
- // actively reading
746
- GRPC_CHTTP2_STREAM_REF(s, "chttp2");
747
- GRPC_CHTTP2_REF_TRANSPORT(s->t, "stream");
748
- }
749
-
750
760
  grpc_chttp2_stream::grpc_chttp2_stream(grpc_chttp2_transport* t,
751
761
  grpc_stream_refcount* refcount,
752
762
  const void* server_data,
753
763
  grpc_core::Arena* arena)
754
- : t(t),
755
- refcount(refcount),
756
- reffer(this),
764
+ : t(t->Ref()),
765
+ refcount([refcount]() {
766
+ // We reserve one 'active stream' that's dropped when the stream is
767
+ // read-closed. The others are for Chttp2IncomingByteStreams that are
768
+ // actively reading
769
+ // We do this here to avoid cache misses.
770
+ #ifndef NDEBUG
771
+ grpc_stream_ref(refcount, "chttp2");
772
+ #else
773
+ grpc_stream_ref(refcount);
774
+ #endif
775
+ return refcount;
776
+ }()),
757
777
  initial_metadata_buffer(arena),
758
778
  trailing_metadata_buffer(arena),
759
779
  flow_control(&t->flow_control) {
@@ -773,8 +793,8 @@ grpc_chttp2_stream::grpc_chttp2_stream(grpc_chttp2_transport* t,
773
793
  }
774
794
 
775
795
  grpc_chttp2_stream::~grpc_chttp2_stream() {
776
- grpc_chttp2_list_remove_stalled_by_stream(t, this);
777
- grpc_chttp2_list_remove_stalled_by_transport(t, this);
796
+ grpc_chttp2_list_remove_stalled_by_stream(t.get(), this);
797
+ grpc_chttp2_list_remove_stalled_by_transport(t.get(), this);
778
798
 
779
799
  if (t->channelz_socket != nullptr) {
780
800
  if ((t->is_client && eos_received) || (!t->is_client && eos_sent)) {
@@ -805,7 +825,6 @@ grpc_chttp2_stream::~grpc_chttp2_stream() {
805
825
  GPR_ASSERT(recv_message_ready == nullptr);
806
826
  GPR_ASSERT(recv_trailing_metadata_finished == nullptr);
807
827
  grpc_slice_buffer_destroy(&flow_controlled_buffer);
808
- GRPC_CHTTP2_UNREF_TRANSPORT(t, "stream");
809
828
  grpc_core::ExecCtx::Run(DEBUG_LOCATION, destroy_stream_arg, absl::OkStatus());
810
829
  }
811
830
 
@@ -893,7 +912,6 @@ void grpc_chttp2_initiate_write(grpc_chttp2_transport* t,
893
912
  case GRPC_CHTTP2_WRITE_STATE_IDLE:
894
913
  set_write_state(t, GRPC_CHTTP2_WRITE_STATE_WRITING,
895
914
  grpc_chttp2_initiate_write_reason_string(reason));
896
- GRPC_CHTTP2_REF_TRANSPORT(t, "writing");
897
915
  // Note that the 'write_action_begin_locked' closure is being scheduled
898
916
  // on the 'finally_scheduler' of t->combiner. This means that
899
917
  // 'write_action_begin_locked' is called only *after* all the other
@@ -911,8 +929,8 @@ void grpc_chttp2_initiate_write(grpc_chttp2_transport* t,
911
929
  // It does not call the endpoint to write the bytes. That is done by the
912
930
  // 'write_action' (which is scheduled by 'write_action_begin_locked')
913
931
  t->combiner->FinallyRun(
914
- GRPC_CLOSURE_INIT(&t->write_action_begin_locked,
915
- write_action_begin_locked, t, nullptr),
932
+ grpc_core::InitTransportClosure<write_action_begin_locked>(
933
+ t->Ref(), &t->write_action_begin_locked),
916
934
  absl::OkStatus());
917
935
  break;
918
936
  case GRPC_CHTTP2_WRITE_STATE_WRITING:
@@ -939,22 +957,22 @@ static const char* begin_writing_desc(bool partial) {
939
957
  }
940
958
  }
941
959
 
942
- static void write_action_begin_locked(void* gt,
943
- grpc_error_handle /*error_ignored*/) {
944
- grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(gt);
960
+ static void write_action_begin_locked(
961
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t,
962
+ grpc_error_handle /*error_ignored*/) {
945
963
  GPR_ASSERT(t->write_state != GRPC_CHTTP2_WRITE_STATE_IDLE);
946
964
  grpc_chttp2_begin_write_result r;
947
965
  if (!t->closed_with_error.ok()) {
948
966
  r.writing = false;
949
967
  } else {
950
- r = grpc_chttp2_begin_write(t);
968
+ r = grpc_chttp2_begin_write(t.get());
951
969
  }
952
970
  if (r.writing) {
953
- set_write_state(t,
971
+ set_write_state(t.get(),
954
972
  r.partial ? GRPC_CHTTP2_WRITE_STATE_WRITING_WITH_MORE
955
973
  : GRPC_CHTTP2_WRITE_STATE_WRITING,
956
974
  begin_writing_desc(r.partial));
957
- write_action(t, absl::OkStatus());
975
+ write_action(t.get());
958
976
  if (t->reading_paused_on_pending_induced_frames) {
959
977
  GPR_ASSERT(t->num_pending_induced_frames == 0);
960
978
  // We had paused reading, because we had many induced frames (SETTINGS
@@ -964,18 +982,17 @@ static void write_action_begin_locked(void* gt,
964
982
  GPR_INFO,
965
983
  "transport %p : Resuming reading after being paused due to too "
966
984
  "many unwritten SETTINGS ACK, PINGS ACK and RST_STREAM frames",
967
- t));
985
+ t.get()));
968
986
  t->reading_paused_on_pending_induced_frames = false;
969
- continue_read_action_locked(t);
987
+ continue_read_action_locked(std::move(t));
970
988
  }
971
989
  } else {
972
- set_write_state(t, GRPC_CHTTP2_WRITE_STATE_IDLE, "begin writing nothing");
973
- GRPC_CHTTP2_UNREF_TRANSPORT(t, "writing");
990
+ set_write_state(t.get(), GRPC_CHTTP2_WRITE_STATE_IDLE,
991
+ "begin writing nothing");
974
992
  }
975
993
  }
976
994
 
977
- static void write_action(void* gt, grpc_error_handle /*error*/) {
978
- grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(gt);
995
+ static void write_action(grpc_chttp2_transport* t) {
979
996
  void* cl = t->cl;
980
997
  if (!t->cl->empty()) {
981
998
  // Transfer the ownership of the context list to the endpoint and create and
@@ -999,28 +1016,28 @@ static void write_action(void* gt, grpc_error_handle /*error*/) {
999
1016
  if (max_frame_size == 0) {
1000
1017
  max_frame_size = INT_MAX;
1001
1018
  }
1002
- grpc_endpoint_write(
1003
- t->ep, &t->outbuf,
1004
- GRPC_CLOSURE_INIT(&t->write_action_end_locked, write_action_end, t,
1005
- grpc_schedule_on_exec_ctx),
1006
- cl, max_frame_size);
1019
+ grpc_endpoint_write(t->ep, &t->outbuf,
1020
+ grpc_core::InitTransportClosure<write_action_end>(
1021
+ t->Ref(), &t->write_action_end_locked),
1022
+ cl, max_frame_size);
1007
1023
  }
1008
1024
 
1009
- static void write_action_end(void* tp, grpc_error_handle error) {
1010
- grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(tp);
1011
- t->combiner->Run(GRPC_CLOSURE_INIT(&t->write_action_end_locked,
1012
- write_action_end_locked, t, nullptr),
1013
- error);
1025
+ static void write_action_end(grpc_core::RefCountedPtr<grpc_chttp2_transport> t,
1026
+ grpc_error_handle error) {
1027
+ auto* tp = t.get();
1028
+ tp->combiner->Run(grpc_core::InitTransportClosure<write_action_end_locked>(
1029
+ std::move(t), &tp->write_action_end_locked),
1030
+ error);
1014
1031
  }
1015
1032
 
1016
1033
  // Callback from the grpc_endpoint after bytes have been written by calling
1017
1034
  // sendmsg
1018
- static void write_action_end_locked(void* tp, grpc_error_handle error) {
1019
- grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(tp);
1020
-
1035
+ static void write_action_end_locked(
1036
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t,
1037
+ grpc_error_handle error) {
1021
1038
  bool closed = false;
1022
1039
  if (!error.ok()) {
1023
- close_transport_locked(t, error);
1040
+ close_transport_locked(t.get(), error);
1024
1041
  closed = true;
1025
1042
  }
1026
1043
 
@@ -1028,7 +1045,7 @@ static void write_action_end_locked(void* tp, grpc_error_handle error) {
1028
1045
  t->sent_goaway_state = GRPC_CHTTP2_FINAL_GOAWAY_SENT;
1029
1046
  closed = true;
1030
1047
  if (t->stream_map.empty()) {
1031
- close_transport_locked(t, GRPC_ERROR_CREATE("goaway sent"));
1048
+ close_transport_locked(t.get(), GRPC_ERROR_CREATE("goaway sent"));
1032
1049
  }
1033
1050
  }
1034
1051
 
@@ -1036,11 +1053,11 @@ static void write_action_end_locked(void* tp, grpc_error_handle error) {
1036
1053
  case GRPC_CHTTP2_WRITE_STATE_IDLE:
1037
1054
  GPR_UNREACHABLE_CODE(break);
1038
1055
  case GRPC_CHTTP2_WRITE_STATE_WRITING:
1039
- set_write_state(t, GRPC_CHTTP2_WRITE_STATE_IDLE, "finish writing");
1056
+ set_write_state(t.get(), GRPC_CHTTP2_WRITE_STATE_IDLE, "finish writing");
1040
1057
  break;
1041
1058
  case GRPC_CHTTP2_WRITE_STATE_WRITING_WITH_MORE:
1042
- set_write_state(t, GRPC_CHTTP2_WRITE_STATE_WRITING, "continue writing");
1043
- GRPC_CHTTP2_REF_TRANSPORT(t, "writing");
1059
+ set_write_state(t.get(), GRPC_CHTTP2_WRITE_STATE_WRITING,
1060
+ "continue writing");
1044
1061
  // If the transport is closed, we will retry writing on the endpoint
1045
1062
  // and next write may contain part of the currently serialized frames.
1046
1063
  // So, we should only call the run_after_write callbacks when the next
@@ -1050,14 +1067,13 @@ static void write_action_end_locked(void* tp, grpc_error_handle error) {
1050
1067
  grpc_core::ExecCtx::RunList(DEBUG_LOCATION, &t->run_after_write);
1051
1068
  }
1052
1069
  t->combiner->FinallyRun(
1053
- GRPC_CLOSURE_INIT(&t->write_action_begin_locked,
1054
- write_action_begin_locked, t, nullptr),
1070
+ grpc_core::InitTransportClosure<write_action_begin_locked>(
1071
+ t, &t->write_action_begin_locked),
1055
1072
  absl::OkStatus());
1056
1073
  break;
1057
1074
  }
1058
1075
 
1059
- grpc_chttp2_end_write(t, error);
1060
- GRPC_CHTTP2_UNREF_TRANSPORT(t, "writing");
1076
+ grpc_chttp2_end_write(t.get(), error);
1061
1077
  }
1062
1078
 
1063
1079
  // Dirties an HTTP2 setting to be sent out next time a writing path occurs.
@@ -1130,7 +1146,7 @@ void grpc_chttp2_add_incoming_goaway(grpc_chttp2_transport* t,
1130
1146
  s->trailing_metadata_buffer.Set(
1131
1147
  grpc_core::GrpcStreamNetworkState(),
1132
1148
  grpc_core::GrpcStreamNetworkState::kNotSeenByServer);
1133
- grpc_chttp2_cancel_stream(s->t, s, s->t->goaway_error);
1149
+ grpc_chttp2_cancel_stream(s->t.get(), s, s->t->goaway_error);
1134
1150
  }
1135
1151
  }
1136
1152
  absl::Status status = grpc_error_to_absl_status(t->goaway_error);
@@ -1319,7 +1335,7 @@ static void perform_stream_op_locked(void* stream_op,
1319
1335
  grpc_chttp2_stream* s =
1320
1336
  static_cast<grpc_chttp2_stream*>(op->handler_private.extra_arg);
1321
1337
  grpc_transport_stream_op_batch_payload* op_payload = op->payload;
1322
- grpc_chttp2_transport* t = s->t;
1338
+ grpc_chttp2_transport* t = s->t.get();
1323
1339
 
1324
1340
  s->context = op->payload->context;
1325
1341
  s->traced = op->is_traced;
@@ -1627,56 +1643,61 @@ static void send_ping_locked(grpc_chttp2_transport* t,
1627
1643
  // Specialized form of send_ping_locked for keepalive ping. If there is already
1628
1644
  // a ping in progress, the keepalive ping would piggyback onto that ping,
1629
1645
  // instead of waiting for that ping to complete and then starting a new ping.
1630
- static void send_keepalive_ping_locked(grpc_chttp2_transport* t) {
1646
+ static void send_keepalive_ping_locked(
1647
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t) {
1631
1648
  if (!t->closed_with_error.ok()) {
1632
- t->combiner->Run(GRPC_CLOSURE_INIT(&t->start_keepalive_ping_locked,
1633
- start_keepalive_ping_locked, t, nullptr),
1634
- t->closed_with_error);
1635
1649
  t->combiner->Run(
1636
- GRPC_CLOSURE_INIT(&t->finish_keepalive_ping_locked,
1637
- finish_keepalive_ping_locked, t, nullptr),
1650
+ grpc_core::InitTransportClosure<start_keepalive_ping_locked>(
1651
+ t->Ref(), &t->start_keepalive_ping_locked),
1652
+ t->closed_with_error);
1653
+ t->combiner->Run(
1654
+ grpc_core::InitTransportClosure<finish_keepalive_ping_locked>(
1655
+ t->Ref(), &t->finish_keepalive_ping_locked),
1638
1656
  t->closed_with_error);
1639
1657
  return;
1640
1658
  }
1641
1659
  grpc_chttp2_ping_queue* pq = &t->ping_queue;
1642
1660
  if (!grpc_closure_list_empty(pq->lists[GRPC_CHTTP2_PCL_INFLIGHT])) {
1643
1661
  // There is a ping in flight. Add yourself to the inflight closure list.
1644
- t->combiner->Run(GRPC_CLOSURE_INIT(&t->start_keepalive_ping_locked,
1645
- start_keepalive_ping_locked, t, nullptr),
1646
- t->closed_with_error);
1662
+ t->combiner->Run(
1663
+ grpc_core::InitTransportClosure<start_keepalive_ping_locked>(
1664
+ t->Ref(), &t->start_keepalive_ping_locked),
1665
+ t->closed_with_error);
1647
1666
  grpc_closure_list_append(
1648
1667
  &pq->lists[GRPC_CHTTP2_PCL_INFLIGHT],
1649
- GRPC_CLOSURE_INIT(&t->finish_keepalive_ping_locked,
1650
- finish_keepalive_ping, t, grpc_schedule_on_exec_ctx),
1668
+ grpc_core::InitTransportClosure<finish_keepalive_ping>(
1669
+ t->Ref(), &t->finish_keepalive_ping_locked),
1651
1670
  absl::OkStatus());
1652
1671
  return;
1653
1672
  }
1654
1673
  grpc_closure_list_append(
1655
1674
  &pq->lists[GRPC_CHTTP2_PCL_INITIATE],
1656
- GRPC_CLOSURE_INIT(&t->start_keepalive_ping_locked, start_keepalive_ping,
1657
- t, grpc_schedule_on_exec_ctx),
1675
+ grpc_core::InitTransportClosure<start_keepalive_ping>(
1676
+ t->Ref(), &t->start_keepalive_ping_locked),
1658
1677
  absl::OkStatus());
1659
1678
  grpc_closure_list_append(
1660
1679
  &pq->lists[GRPC_CHTTP2_PCL_NEXT],
1661
- GRPC_CLOSURE_INIT(&t->finish_keepalive_ping_locked, finish_keepalive_ping,
1662
- t, grpc_schedule_on_exec_ctx),
1680
+ grpc_core::InitTransportClosure<finish_keepalive_ping>(
1681
+ t->Ref(), &t->finish_keepalive_ping_locked),
1663
1682
  absl::OkStatus());
1664
1683
  }
1665
1684
 
1666
- void grpc_chttp2_retry_initiate_ping(grpc_chttp2_transport* t) {
1667
- t->combiner->Run(GRPC_CLOSURE_INIT(&t->retry_initiate_ping_locked,
1668
- retry_initiate_ping_locked, t, nullptr),
1669
- absl::OkStatus());
1685
+ void grpc_chttp2_retry_initiate_ping(
1686
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t) {
1687
+ auto tp = t.get();
1688
+ tp->combiner->Run(grpc_core::InitTransportClosure<retry_initiate_ping_locked>(
1689
+ std::move(t), &tp->retry_initiate_ping_locked),
1690
+ absl::OkStatus());
1670
1691
  }
1671
1692
 
1672
- static void retry_initiate_ping_locked(void* tp,
1673
- GRPC_UNUSED grpc_error_handle error) {
1693
+ static void retry_initiate_ping_locked(
1694
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t,
1695
+ GRPC_UNUSED grpc_error_handle error) {
1674
1696
  GPR_DEBUG_ASSERT(error.ok());
1675
- grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(tp);
1676
- GPR_ASSERT(t->ping_state.delayed_ping_timer_handle.has_value());
1677
- t->ping_state.delayed_ping_timer_handle.reset();
1678
- grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_RETRY_SEND_PING);
1679
- GRPC_CHTTP2_UNREF_TRANSPORT(t, "retry_initiate_ping_locked");
1697
+ GPR_ASSERT(t->delayed_ping_timer_handle.has_value());
1698
+ t->delayed_ping_timer_handle.reset();
1699
+ grpc_chttp2_initiate_write(t.get(),
1700
+ GRPC_CHTTP2_INITIATE_WRITE_RETRY_SEND_PING);
1680
1701
  }
1681
1702
 
1682
1703
  void grpc_chttp2_ack_ping(grpc_chttp2_transport* t, uint64_t id) {
@@ -1706,16 +1727,11 @@ class GracefulGoaway : public grpc_core::RefCounted<GracefulGoaway> {
1706
1727
  public:
1707
1728
  static void Start(grpc_chttp2_transport* t) { new GracefulGoaway(t); }
1708
1729
 
1709
- ~GracefulGoaway() override {
1710
- GRPC_CHTTP2_UNREF_TRANSPORT(t_, "graceful goaway");
1711
- }
1712
-
1713
1730
  private:
1714
1731
  using TaskHandle = ::grpc_event_engine::experimental::EventEngine::TaskHandle;
1715
1732
 
1716
- explicit GracefulGoaway(grpc_chttp2_transport* t) : t_(t) {
1733
+ explicit GracefulGoaway(grpc_chttp2_transport* t) : t_(t->Ref()) {
1717
1734
  t->sent_goaway_state = GRPC_CHTTP2_GRACEFUL_GOAWAY;
1718
- GRPC_CHTTP2_REF_TRANSPORT(t_, "graceful goaway");
1719
1735
  grpc_chttp2_goaway_append((1u << 31) - 1, 0, grpc_empty_slice(), &t->qbuf);
1720
1736
  send_ping_locked(
1721
1737
  t, nullptr, GRPC_CLOSURE_INIT(&on_ping_ack_, OnPingAck, this, nullptr));
@@ -1743,7 +1759,7 @@ class GracefulGoaway : public grpc_core::RefCounted<GracefulGoaway> {
1743
1759
  gpr_log(GPR_INFO,
1744
1760
  "transport:%p %s peer:%s Transport already shutting down. "
1745
1761
  "Graceful GOAWAY abandoned.",
1746
- t_, t_->is_client ? "CLIENT" : "SERVER",
1762
+ t_.get(), t_->is_client ? "CLIENT" : "SERVER",
1747
1763
  std::string(t_->peer_string.as_string_view()).c_str()));
1748
1764
  return;
1749
1765
  }
@@ -1752,13 +1768,14 @@ class GracefulGoaway : public grpc_core::RefCounted<GracefulGoaway> {
1752
1768
  gpr_log(GPR_INFO,
1753
1769
  "transport:%p %s peer:%s Graceful shutdown: Ping received. "
1754
1770
  "Sending final GOAWAY with stream_id:%d",
1755
- t_, t_->is_client ? "CLIENT" : "SERVER",
1771
+ t_.get(), t_->is_client ? "CLIENT" : "SERVER",
1756
1772
  std::string(t_->peer_string.as_string_view()).c_str(),
1757
1773
  t_->last_new_stream_id));
1758
1774
  t_->sent_goaway_state = GRPC_CHTTP2_FINAL_GOAWAY_SEND_SCHEDULED;
1759
1775
  grpc_chttp2_goaway_append(t_->last_new_stream_id, 0, grpc_empty_slice(),
1760
1776
  &t_->qbuf);
1761
- grpc_chttp2_initiate_write(t_, GRPC_CHTTP2_INITIATE_WRITE_GOAWAY_SENT);
1777
+ grpc_chttp2_initiate_write(t_.get(),
1778
+ GRPC_CHTTP2_INITIATE_WRITE_GOAWAY_SENT);
1762
1779
  }
1763
1780
 
1764
1781
  static void OnPingAck(void* arg, grpc_error_handle /* error */) {
@@ -1786,7 +1803,7 @@ class GracefulGoaway : public grpc_core::RefCounted<GracefulGoaway> {
1786
1803
  self->Unref();
1787
1804
  }
1788
1805
 
1789
- grpc_chttp2_transport* t_;
1806
+ const grpc_core::RefCountedPtr<grpc_chttp2_transport> t_;
1790
1807
  grpc_closure on_ping_ack_;
1791
1808
  TaskHandle timer_handle_ = TaskHandle::kInvalid;
1792
1809
  grpc_closure on_timer_;
@@ -1825,39 +1842,34 @@ static void send_goaway(grpc_chttp2_transport* t, grpc_error_handle error,
1825
1842
  grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_GOAWAY_SENT);
1826
1843
  }
1827
1844
 
1828
- void grpc_chttp2_add_ping_strike(grpc_chttp2_transport* t) {
1829
- if (++t->ping_recv_state.ping_strikes > t->ping_policy.max_ping_strikes &&
1830
- t->ping_policy.max_ping_strikes != 0) {
1831
- send_goaway(t,
1832
- grpc_error_set_int(GRPC_ERROR_CREATE("too_many_pings"),
1833
- grpc_core::StatusIntProperty::kHttp2Error,
1834
- GRPC_HTTP2_ENHANCE_YOUR_CALM),
1835
- /*immediate_disconnect_hint=*/true);
1836
- // The transport will be closed after the write is done
1837
- close_transport_locked(
1838
- t, grpc_error_set_int(GRPC_ERROR_CREATE("Too many pings"),
1839
- grpc_core::StatusIntProperty::kRpcStatus,
1840
- GRPC_STATUS_UNAVAILABLE));
1841
- }
1845
+ void grpc_chttp2_exceeded_ping_strikes(grpc_chttp2_transport* t) {
1846
+ send_goaway(t,
1847
+ grpc_error_set_int(GRPC_ERROR_CREATE("too_many_pings"),
1848
+ grpc_core::StatusIntProperty::kHttp2Error,
1849
+ GRPC_HTTP2_ENHANCE_YOUR_CALM),
1850
+ /*immediate_disconnect_hint=*/true);
1851
+ // The transport will be closed after the write is done
1852
+ close_transport_locked(
1853
+ t, grpc_error_set_int(GRPC_ERROR_CREATE("Too many pings"),
1854
+ grpc_core::StatusIntProperty::kRpcStatus,
1855
+ GRPC_STATUS_UNAVAILABLE));
1842
1856
  }
1843
1857
 
1844
1858
  void grpc_chttp2_reset_ping_clock(grpc_chttp2_transport* t) {
1845
1859
  if (!t->is_client) {
1846
- t->ping_recv_state.last_ping_recv_time = grpc_core::Timestamp::InfPast();
1847
- t->ping_recv_state.ping_strikes = 0;
1860
+ t->ping_abuse_policy.ResetPingStrikes();
1848
1861
  }
1849
- t->ping_state.pings_before_data_required =
1850
- t->ping_policy.max_pings_without_data;
1862
+ t->ping_rate_policy.ResetPingsBeforeDataRequired();
1851
1863
  }
1852
1864
 
1853
1865
  static void perform_transport_op_locked(void* stream_op,
1854
1866
  grpc_error_handle /*error_ignored*/) {
1855
1867
  grpc_transport_op* op = static_cast<grpc_transport_op*>(stream_op);
1856
- grpc_chttp2_transport* t =
1857
- static_cast<grpc_chttp2_transport*>(op->handler_private.extra_arg);
1868
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t(
1869
+ static_cast<grpc_chttp2_transport*>(op->handler_private.extra_arg));
1858
1870
 
1859
1871
  if (!op->goaway_error.ok()) {
1860
- send_goaway(t, op->goaway_error, /*immediate_disconnect_hint=*/false);
1872
+ send_goaway(t.get(), op->goaway_error, /*immediate_disconnect_hint=*/false);
1861
1873
  }
1862
1874
 
1863
1875
  if (op->set_accept_stream) {
@@ -1874,8 +1886,9 @@ static void perform_transport_op_locked(void* stream_op,
1874
1886
  }
1875
1887
 
1876
1888
  if (op->send_ping.on_initiate != nullptr || op->send_ping.on_ack != nullptr) {
1877
- send_ping_locked(t, op->send_ping.on_initiate, op->send_ping.on_ack);
1878
- grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_APPLICATION_PING);
1889
+ send_ping_locked(t.get(), op->send_ping.on_initiate, op->send_ping.on_ack);
1890
+ grpc_chttp2_initiate_write(t.get(),
1891
+ GRPC_CHTTP2_INITIATE_WRITE_APPLICATION_PING);
1879
1892
  }
1880
1893
 
1881
1894
  if (op->start_connectivity_watch != nullptr) {
@@ -1887,14 +1900,12 @@ static void perform_transport_op_locked(void* stream_op,
1887
1900
  }
1888
1901
 
1889
1902
  if (!op->disconnect_with_error.ok()) {
1890
- send_goaway(t, op->disconnect_with_error,
1903
+ send_goaway(t.get(), op->disconnect_with_error,
1891
1904
  /*immediate_disconnect_hint=*/true);
1892
- close_transport_locked(t, op->disconnect_with_error);
1905
+ close_transport_locked(t.get(), op->disconnect_with_error);
1893
1906
  }
1894
1907
 
1895
1908
  grpc_core::ExecCtx::Run(DEBUG_LOCATION, op->on_consumed, absl::OkStatus());
1896
-
1897
- GRPC_CHTTP2_UNREF_TRANSPORT(t, "transport_op");
1898
1909
  }
1899
1910
 
1900
1911
  static void perform_transport_op(grpc_transport* gt, grpc_transport_op* op) {
@@ -1904,10 +1915,10 @@ static void perform_transport_op(grpc_transport* gt, grpc_transport_op* op) {
1904
1915
  grpc_transport_op_string(op).c_str());
1905
1916
  }
1906
1917
  op->handler_private.extra_arg = gt;
1907
- GRPC_CHTTP2_REF_TRANSPORT(t, "transport_op");
1908
- t->combiner->Run(GRPC_CLOSURE_INIT(&op->handler_private.closure,
1909
- perform_transport_op_locked, op, nullptr),
1910
- absl::OkStatus());
1918
+ t->Ref().release()->combiner->Run(
1919
+ GRPC_CLOSURE_INIT(&op->handler_private.closure,
1920
+ perform_transport_op_locked, op, nullptr),
1921
+ absl::OkStatus());
1911
1922
  }
1912
1923
 
1913
1924
  //
@@ -2504,16 +2515,17 @@ static grpc_error_handle try_http_parsing(grpc_chttp2_transport* t) {
2504
2515
  return error;
2505
2516
  }
2506
2517
 
2507
- static void read_action(void* tp, grpc_error_handle error) {
2508
- grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(tp);
2509
- t->combiner->Run(
2510
- GRPC_CLOSURE_INIT(&t->read_action_locked, read_action_locked, t, nullptr),
2511
- error);
2518
+ static void read_action(grpc_core::RefCountedPtr<grpc_chttp2_transport> t,
2519
+ grpc_error_handle error) {
2520
+ auto* tp = t.get();
2521
+ tp->combiner->Run(grpc_core::InitTransportClosure<read_action_locked>(
2522
+ std::move(t), &tp->read_action_locked),
2523
+ error);
2512
2524
  }
2513
2525
 
2514
- static void read_action_locked(void* tp, grpc_error_handle error) {
2515
- grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(tp);
2516
-
2526
+ static void read_action_locked(
2527
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t,
2528
+ grpc_error_handle error) {
2517
2529
  grpc_error_handle err = error;
2518
2530
  if (!err.ok()) {
2519
2531
  err = grpc_error_set_int(
@@ -2525,10 +2537,10 @@ static void read_action_locked(void* tp, grpc_error_handle error) {
2525
2537
  size_t i = 0;
2526
2538
  grpc_error_handle errors[3] = {error, absl::OkStatus(), absl::OkStatus()};
2527
2539
  for (; i < t->read_buffer.count && errors[1] == absl::OkStatus(); i++) {
2528
- errors[1] = grpc_chttp2_perform_read(t, t->read_buffer.slices[i]);
2540
+ errors[1] = grpc_chttp2_perform_read(t.get(), t->read_buffer.slices[i]);
2529
2541
  }
2530
2542
  if (errors[1] != absl::OkStatus()) {
2531
- errors[2] = try_http_parsing(t);
2543
+ errors[2] = try_http_parsing(t.get());
2532
2544
  error = GRPC_ERROR_CREATE_REFERENCING("Failed parsing HTTP/2", errors,
2533
2545
  GPR_ARRAY_SIZE(errors));
2534
2546
  }
@@ -2536,10 +2548,11 @@ static void read_action_locked(void* tp, grpc_error_handle error) {
2536
2548
  if (t->initial_window_update != 0) {
2537
2549
  if (t->initial_window_update > 0) {
2538
2550
  grpc_chttp2_stream* s;
2539
- while (grpc_chttp2_list_pop_stalled_by_stream(t, &s)) {
2540
- grpc_chttp2_mark_stream_writable(t, s);
2551
+ while (grpc_chttp2_list_pop_stalled_by_stream(t.get(), &s)) {
2552
+ grpc_chttp2_mark_stream_writable(t.get(), s);
2541
2553
  grpc_chttp2_initiate_write(
2542
- t, GRPC_CHTTP2_INITIATE_WRITE_FLOW_CONTROL_UNSTALLED_BY_SETTING);
2554
+ t.get(),
2555
+ GRPC_CHTTP2_INITIATE_WRITE_FLOW_CONTROL_UNSTALLED_BY_SETTING);
2543
2556
  }
2544
2557
  }
2545
2558
  t->initial_window_update = 0;
@@ -2558,13 +2571,13 @@ static void read_action_locked(void* tp, grpc_error_handle error) {
2558
2571
  error = grpc_error_add_child(error, t->goaway_error);
2559
2572
  }
2560
2573
 
2561
- close_transport_locked(t, error);
2574
+ close_transport_locked(t.get(), error);
2562
2575
  t->endpoint_reading = 0;
2563
2576
  } else if (t->closed_with_error.ok()) {
2564
2577
  keep_reading = true;
2565
2578
  // Since we have read a byte, reset the keepalive timer
2566
2579
  if (t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_WAITING) {
2567
- maybe_reset_keepalive_ping_timer_locked(t);
2580
+ maybe_reset_keepalive_ping_timer_locked(t.get());
2568
2581
  }
2569
2582
  }
2570
2583
  grpc_slice_buffer_reset_and_unref(&t->read_buffer);
@@ -2576,45 +2589,48 @@ static void read_action_locked(void* tp, grpc_error_handle error) {
2576
2589
  gpr_log(GPR_INFO,
2577
2590
  "transport %p : Pausing reading due to too "
2578
2591
  "many unwritten SETTINGS ACK and RST_STREAM frames",
2579
- t));
2592
+ t.get()));
2580
2593
  } else {
2581
- continue_read_action_locked(t);
2594
+ continue_read_action_locked(std::move(t));
2582
2595
  }
2583
- } else {
2584
- GRPC_CHTTP2_UNREF_TRANSPORT(t, "reading_action");
2585
2596
  }
2586
2597
  }
2587
2598
 
2588
- static void continue_read_action_locked(grpc_chttp2_transport* t) {
2599
+ static void continue_read_action_locked(
2600
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t) {
2589
2601
  const bool urgent = !t->goaway_error.ok();
2590
- GRPC_CLOSURE_INIT(&t->read_action_locked, read_action, t,
2591
- grpc_schedule_on_exec_ctx);
2592
- grpc_endpoint_read(t->ep, &t->read_buffer, &t->read_action_locked, urgent,
2593
- grpc_chttp2_min_read_progress_size(t));
2602
+ auto* tp = t.get();
2603
+ grpc_endpoint_read(tp->ep, &tp->read_buffer,
2604
+ grpc_core::InitTransportClosure<read_action>(
2605
+ std::move(t), &tp->read_action_locked),
2606
+ urgent, grpc_chttp2_min_read_progress_size(tp));
2594
2607
  }
2595
2608
 
2596
2609
  // t is reffed prior to calling the first time, and once the callback chain
2597
2610
  // that kicks off finishes, it's unreffed
2598
- void schedule_bdp_ping_locked(grpc_chttp2_transport* t) {
2599
- t->flow_control.bdp_estimator()->SchedulePing();
2600
- send_ping_locked(
2601
- t,
2602
- GRPC_CLOSURE_INIT(&t->start_bdp_ping_locked, start_bdp_ping, t,
2603
- grpc_schedule_on_exec_ctx),
2604
- GRPC_CLOSURE_INIT(&t->finish_bdp_ping_locked, finish_bdp_ping, t,
2605
- grpc_schedule_on_exec_ctx));
2606
- grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_BDP_PING);
2607
- }
2608
-
2609
- static void start_bdp_ping(void* tp, grpc_error_handle error) {
2610
- grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(tp);
2611
- t->combiner->Run(GRPC_CLOSURE_INIT(&t->start_bdp_ping_locked,
2612
- start_bdp_ping_locked, t, nullptr),
2613
- error);
2614
- }
2615
-
2616
- static void start_bdp_ping_locked(void* tp, grpc_error_handle error) {
2617
- grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(tp);
2611
+ void schedule_bdp_ping_locked(
2612
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t) {
2613
+ auto* tp = t.get();
2614
+ tp->flow_control.bdp_estimator()->SchedulePing();
2615
+ send_ping_locked(tp,
2616
+ grpc_core::InitTransportClosure<start_bdp_ping>(
2617
+ tp->Ref(), &tp->start_bdp_ping_locked),
2618
+ grpc_core::InitTransportClosure<finish_bdp_ping>(
2619
+ std::move(t), &tp->finish_bdp_ping_locked));
2620
+ grpc_chttp2_initiate_write(tp, GRPC_CHTTP2_INITIATE_WRITE_BDP_PING);
2621
+ }
2622
+
2623
+ static void start_bdp_ping(grpc_core::RefCountedPtr<grpc_chttp2_transport> t,
2624
+ grpc_error_handle error) {
2625
+ grpc_chttp2_transport* tp = t.get();
2626
+ tp->combiner->Run(grpc_core::InitTransportClosure<start_bdp_ping_locked>(
2627
+ std::move(t), &tp->start_bdp_ping_locked),
2628
+ error);
2629
+ }
2630
+
2631
+ static void start_bdp_ping_locked(
2632
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t,
2633
+ grpc_error_handle error) {
2618
2634
  if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) {
2619
2635
  gpr_log(GPR_INFO, "%s: Start BDP ping err=%s",
2620
2636
  std::string(t->peer_string.as_string_view()).c_str(),
@@ -2625,71 +2641,69 @@ static void start_bdp_ping_locked(void* tp, grpc_error_handle error) {
2625
2641
  }
2626
2642
  // Reset the keepalive ping timer
2627
2643
  if (t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_WAITING) {
2628
- maybe_reset_keepalive_ping_timer_locked(t);
2644
+ maybe_reset_keepalive_ping_timer_locked(t.get());
2629
2645
  }
2630
2646
  t->flow_control.bdp_estimator()->StartPing();
2631
2647
  t->bdp_ping_started = true;
2632
2648
  }
2633
2649
 
2634
- static void finish_bdp_ping(void* tp, grpc_error_handle error) {
2635
- grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(tp);
2636
- t->combiner->Run(GRPC_CLOSURE_INIT(&t->finish_bdp_ping_locked,
2637
- finish_bdp_ping_locked, t, nullptr),
2638
- error);
2650
+ static void finish_bdp_ping(grpc_core::RefCountedPtr<grpc_chttp2_transport> t,
2651
+ grpc_error_handle error) {
2652
+ grpc_chttp2_transport* tp = t.get();
2653
+ tp->combiner->Run(grpc_core::InitTransportClosure<finish_bdp_ping_locked>(
2654
+ std::move(t), &tp->finish_bdp_ping_locked),
2655
+ error);
2639
2656
  }
2640
2657
 
2641
- static void finish_bdp_ping_locked(void* tp, grpc_error_handle error) {
2642
- grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(tp);
2658
+ static void finish_bdp_ping_locked(
2659
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t,
2660
+ grpc_error_handle error) {
2643
2661
  if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) {
2644
2662
  gpr_log(GPR_INFO, "%s: Complete BDP ping err=%s",
2645
2663
  std::string(t->peer_string.as_string_view()).c_str(),
2646
2664
  grpc_core::StatusToString(error).c_str());
2647
2665
  }
2648
2666
  if (!error.ok() || !t->closed_with_error.ok()) {
2649
- GRPC_CHTTP2_UNREF_TRANSPORT(t, "bdp_ping");
2650
2667
  return;
2651
2668
  }
2652
2669
  if (!t->bdp_ping_started) {
2653
2670
  // start_bdp_ping_locked has not been run yet. Schedule
2654
2671
  // finish_bdp_ping_locked to be run later.
2655
- t->combiner->Run(GRPC_CLOSURE_INIT(&t->finish_bdp_ping_locked,
2656
- finish_bdp_ping_locked, t, nullptr),
2657
- error);
2672
+ finish_bdp_ping(std::move(t), std::move(error));
2658
2673
  return;
2659
2674
  }
2660
2675
  t->bdp_ping_started = false;
2661
2676
  grpc_core::Timestamp next_ping =
2662
2677
  t->flow_control.bdp_estimator()->CompletePing();
2663
- grpc_chttp2_act_on_flowctl_action(t->flow_control.PeriodicUpdate(), t,
2678
+ grpc_chttp2_act_on_flowctl_action(t->flow_control.PeriodicUpdate(), t.get(),
2664
2679
  nullptr);
2665
2680
  GPR_ASSERT(!t->next_bdp_ping_timer_handle.has_value());
2666
2681
  t->next_bdp_ping_timer_handle =
2667
2682
  t->event_engine->RunAfter(next_ping - grpc_core::Timestamp::Now(), [t] {
2668
2683
  grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
2669
2684
  grpc_core::ExecCtx exec_ctx;
2670
- next_bdp_ping_timer_expired(t);
2685
+ next_bdp_ping_timer_expired(t.get());
2671
2686
  });
2672
2687
  }
2673
2688
 
2674
2689
  static void next_bdp_ping_timer_expired(grpc_chttp2_transport* t) {
2675
2690
  t->combiner->Run(
2676
- GRPC_CLOSURE_INIT(&t->next_bdp_ping_timer_expired_locked,
2677
- next_bdp_ping_timer_expired_locked, t, nullptr),
2691
+ grpc_core::InitTransportClosure<next_bdp_ping_timer_expired_locked>(
2692
+ t->Ref(), &t->next_bdp_ping_timer_expired_locked),
2678
2693
  absl::OkStatus());
2679
2694
  }
2680
2695
 
2681
2696
  static void next_bdp_ping_timer_expired_locked(
2682
- void* tp, GRPC_UNUSED grpc_error_handle error) {
2697
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t,
2698
+ GRPC_UNUSED grpc_error_handle error) {
2683
2699
  GPR_DEBUG_ASSERT(error.ok());
2684
- grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(tp);
2685
2700
  GPR_ASSERT(t->next_bdp_ping_timer_handle.has_value());
2686
2701
  t->next_bdp_ping_timer_handle.reset();
2687
2702
  if (t->flow_control.bdp_estimator()->accumulator() == 0) {
2688
2703
  // Block the bdp ping till we receive more data.
2689
2704
  t->bdp_ping_blocked = true;
2690
- GRPC_CHTTP2_UNREF_TRANSPORT(t, "bdp_ping");
2691
2705
  } else {
2692
- schedule_bdp_ping_locked(t);
2706
+ schedule_bdp_ping_locked(std::move(t));
2693
2707
  }
2694
2708
  }
2695
2709
 
@@ -2736,32 +2750,22 @@ void grpc_chttp2_config_default_keepalive_args(
2736
2750
  keepalive_permit_without_calls;
2737
2751
  }
2738
2752
 
2739
- g_default_max_ping_strikes =
2740
- std::max(0, channel_args.GetInt(GRPC_ARG_HTTP2_MAX_PING_STRIKES)
2741
- .value_or(g_default_max_ping_strikes));
2742
-
2743
- g_default_max_pings_without_data =
2744
- std::max(0, channel_args.GetInt(GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA)
2745
- .value_or(g_default_max_pings_without_data));
2746
-
2747
- g_default_min_recv_ping_interval_without_data =
2748
- std::max(grpc_core::Duration::Zero(),
2749
- channel_args
2750
- .GetDurationFromIntMillis(
2751
- GRPC_ARG_HTTP2_MIN_RECV_PING_INTERVAL_WITHOUT_DATA_MS)
2752
- .value_or(g_default_min_recv_ping_interval_without_data));
2753
+ grpc_core::Chttp2PingAbusePolicy::SetDefaults(channel_args);
2754
+ grpc_core::Chttp2PingRatePolicy::SetDefaults(channel_args);
2753
2755
  }
2754
2756
 
2755
- static void init_keepalive_ping(grpc_chttp2_transport* t) {
2756
- t->combiner->Run(GRPC_CLOSURE_INIT(&t->init_keepalive_ping_locked,
2757
- init_keepalive_ping_locked, t, nullptr),
2758
- absl::OkStatus());
2757
+ static void init_keepalive_ping(
2758
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t) {
2759
+ auto* tp = t.get();
2760
+ tp->combiner->Run(grpc_core::InitTransportClosure<init_keepalive_ping_locked>(
2761
+ std::move(t), &tp->init_keepalive_ping_locked),
2762
+ absl::OkStatus());
2759
2763
  }
2760
2764
 
2761
- static void init_keepalive_ping_locked(void* arg,
2762
- GRPC_UNUSED grpc_error_handle error) {
2765
+ static void init_keepalive_ping_locked(
2766
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t,
2767
+ GRPC_UNUSED grpc_error_handle error) {
2763
2768
  GPR_DEBUG_ASSERT(error.ok());
2764
- grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(arg);
2765
2769
  GPR_ASSERT(t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_WAITING);
2766
2770
  GPR_ASSERT(t->keepalive_ping_timer_handle.has_value());
2767
2771
  t->keepalive_ping_timer_handle.reset();
@@ -2770,11 +2774,10 @@ static void init_keepalive_ping_locked(void* arg,
2770
2774
  } else {
2771
2775
  if (t->keepalive_permit_without_calls || !t->stream_map.empty()) {
2772
2776
  t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_PINGING;
2773
- GRPC_CHTTP2_REF_TRANSPORT(t, "keepalive ping end");
2774
2777
  send_keepalive_ping_locked(t);
2775
- grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_KEEPALIVE_PING);
2778
+ grpc_chttp2_initiate_write(t.get(),
2779
+ GRPC_CHTTP2_INITIATE_WRITE_KEEPALIVE_PING);
2776
2780
  } else {
2777
- GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping");
2778
2781
  t->keepalive_ping_timer_handle =
2779
2782
  t->event_engine->RunAfter(t->keepalive_time, [t] {
2780
2783
  grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
@@ -2783,18 +2786,21 @@ static void init_keepalive_ping_locked(void* arg,
2783
2786
  });
2784
2787
  }
2785
2788
  }
2786
- GRPC_CHTTP2_UNREF_TRANSPORT(t, "init keepalive ping");
2787
2789
  }
2788
2790
 
2789
- static void start_keepalive_ping(void* arg, grpc_error_handle error) {
2790
- grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(arg);
2791
- t->combiner->Run(GRPC_CLOSURE_INIT(&t->start_keepalive_ping_locked,
2792
- start_keepalive_ping_locked, t, nullptr),
2793
- error);
2791
+ static void start_keepalive_ping(
2792
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t,
2793
+ grpc_error_handle error) {
2794
+ auto* tp = t.get();
2795
+ tp->combiner->Run(
2796
+ grpc_core::InitTransportClosure<start_keepalive_ping_locked>(
2797
+ std::move(t), &tp->start_keepalive_ping_locked),
2798
+ error);
2794
2799
  }
2795
2800
 
2796
- static void start_keepalive_ping_locked(void* arg, grpc_error_handle error) {
2797
- grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(arg);
2801
+ static void start_keepalive_ping_locked(
2802
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t,
2803
+ grpc_error_handle error) {
2798
2804
  if (!error.ok()) {
2799
2805
  return;
2800
2806
  }
@@ -2806,25 +2812,28 @@ static void start_keepalive_ping_locked(void* arg, grpc_error_handle error) {
2806
2812
  gpr_log(GPR_INFO, "%s: Start keepalive ping",
2807
2813
  std::string(t->peer_string.as_string_view()).c_str());
2808
2814
  }
2809
- GRPC_CHTTP2_REF_TRANSPORT(t, "keepalive watchdog");
2810
2815
  t->keepalive_watchdog_timer_handle =
2811
- t->event_engine->RunAfter(t->keepalive_timeout, [t] {
2816
+ t->event_engine->RunAfter(t->keepalive_timeout, [t]() mutable {
2812
2817
  grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
2813
2818
  grpc_core::ExecCtx exec_ctx;
2814
- keepalive_watchdog_fired(t);
2819
+ keepalive_watchdog_fired(std::move(t));
2815
2820
  });
2816
2821
  t->keepalive_ping_started = true;
2817
2822
  }
2818
2823
 
2819
- static void finish_keepalive_ping(void* arg, grpc_error_handle error) {
2820
- grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(arg);
2821
- t->combiner->Run(GRPC_CLOSURE_INIT(&t->finish_keepalive_ping_locked,
2822
- finish_keepalive_ping_locked, t, nullptr),
2823
- error);
2824
+ static void finish_keepalive_ping(
2825
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t,
2826
+ grpc_error_handle error) {
2827
+ auto* tp = t.get();
2828
+ tp->combiner->Run(
2829
+ grpc_core::InitTransportClosure<finish_keepalive_ping_locked>(
2830
+ std::move(t), &tp->finish_keepalive_ping_locked),
2831
+ error);
2824
2832
  }
2825
2833
 
2826
- static void finish_keepalive_ping_locked(void* arg, grpc_error_handle error) {
2827
- grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(arg);
2834
+ static void finish_keepalive_ping_locked(
2835
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t,
2836
+ grpc_error_handle error) {
2828
2837
  if (t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_PINGING) {
2829
2838
  if (error.ok()) {
2830
2839
  if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace) ||
@@ -2835,22 +2844,17 @@ static void finish_keepalive_ping_locked(void* arg, grpc_error_handle error) {
2835
2844
  if (!t->keepalive_ping_started) {
2836
2845
  // start_keepalive_ping_locked has not run yet. Reschedule
2837
2846
  // finish_keepalive_ping_locked for it to be run later.
2838
- t->combiner->Run(
2839
- GRPC_CLOSURE_INIT(&t->finish_keepalive_ping_locked,
2840
- finish_keepalive_ping_locked, t, nullptr),
2841
- error);
2847
+ finish_keepalive_ping(std::move(t), std::move(error));
2842
2848
  return;
2843
2849
  }
2844
2850
  t->keepalive_ping_started = false;
2845
2851
  t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_WAITING;
2846
2852
  if (t->keepalive_watchdog_timer_handle.has_value()) {
2847
2853
  if (t->event_engine->Cancel(*t->keepalive_watchdog_timer_handle)) {
2848
- GRPC_CHTTP2_UNREF_TRANSPORT(t, "keepalive watchdog");
2849
2854
  t->keepalive_watchdog_timer_handle.reset();
2850
2855
  }
2851
2856
  }
2852
2857
  GPR_ASSERT(!t->keepalive_ping_timer_handle.has_value());
2853
- GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping");
2854
2858
  t->keepalive_ping_timer_handle =
2855
2859
  t->event_engine->RunAfter(t->keepalive_time, [t] {
2856
2860
  grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
@@ -2859,20 +2863,21 @@ static void finish_keepalive_ping_locked(void* arg, grpc_error_handle error) {
2859
2863
  });
2860
2864
  }
2861
2865
  }
2862
- GRPC_CHTTP2_UNREF_TRANSPORT(t, "keepalive ping end");
2863
2866
  }
2864
2867
 
2865
- static void keepalive_watchdog_fired(grpc_chttp2_transport* t) {
2866
- t->combiner->Run(
2867
- GRPC_CLOSURE_INIT(&t->keepalive_watchdog_fired_locked,
2868
- keepalive_watchdog_fired_locked, t, nullptr),
2868
+ static void keepalive_watchdog_fired(
2869
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t) {
2870
+ auto* tp = t.get();
2871
+ tp->combiner->Run(
2872
+ grpc_core::InitTransportClosure<keepalive_watchdog_fired_locked>(
2873
+ std::move(t), &tp->keepalive_watchdog_fired_locked),
2869
2874
  absl::OkStatus());
2870
2875
  }
2871
2876
 
2872
2877
  static void keepalive_watchdog_fired_locked(
2873
- void* arg, GRPC_UNUSED grpc_error_handle error) {
2878
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t,
2879
+ GRPC_UNUSED grpc_error_handle error) {
2874
2880
  GPR_DEBUG_ASSERT(error.ok());
2875
- grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(arg);
2876
2881
  GPR_ASSERT(t->keepalive_watchdog_timer_handle.has_value());
2877
2882
  t->keepalive_watchdog_timer_handle.reset();
2878
2883
  if (t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_PINGING) {
@@ -2880,9 +2885,10 @@ static void keepalive_watchdog_fired_locked(
2880
2885
  std::string(t->peer_string.as_string_view()).c_str());
2881
2886
  t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_DYING;
2882
2887
  close_transport_locked(
2883
- t, grpc_error_set_int(GRPC_ERROR_CREATE("keepalive watchdog timeout"),
2884
- grpc_core::StatusIntProperty::kRpcStatus,
2885
- GRPC_STATUS_UNAVAILABLE));
2888
+ t.get(),
2889
+ grpc_error_set_int(GRPC_ERROR_CREATE("keepalive watchdog timeout"),
2890
+ grpc_core::StatusIntProperty::kRpcStatus,
2891
+ GRPC_STATUS_UNAVAILABLE));
2886
2892
  } else {
2887
2893
  // If keepalive_state is not PINGING, we consider it as an error. Maybe the
2888
2894
  // cancellation failed in finish_keepalive_ping_locked. Users have seen
@@ -2890,7 +2896,6 @@ static void keepalive_watchdog_fired_locked(
2890
2896
  gpr_log(GPR_ERROR, "keepalive_ping_end state error: %d (expect: %d)",
2891
2897
  t->keepalive_state, GRPC_CHTTP2_KEEPALIVE_STATE_PINGING);
2892
2898
  }
2893
- GRPC_CHTTP2_UNREF_TRANSPORT(t, "keepalive watchdog");
2894
2899
  }
2895
2900
 
2896
2901
  static void maybe_reset_keepalive_ping_timer_locked(grpc_chttp2_transport* t) {
@@ -2903,11 +2908,11 @@ static void maybe_reset_keepalive_ping_timer_locked(grpc_chttp2_transport* t) {
2903
2908
  gpr_log(GPR_INFO, "%s: Keepalive ping cancelled. Resetting timer.",
2904
2909
  std::string(t->peer_string.as_string_view()).c_str());
2905
2910
  }
2906
- t->keepalive_ping_timer_handle =
2907
- t->event_engine->RunAfter(t->keepalive_time, [t] {
2911
+ t->keepalive_ping_timer_handle = t->event_engine->RunAfter(
2912
+ t->keepalive_time, [t = t->Ref()]() mutable {
2908
2913
  grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
2909
2914
  grpc_core::ExecCtx exec_ctx;
2910
- init_keepalive_ping(t);
2915
+ init_keepalive_ping(std::move(t));
2911
2916
  });
2912
2917
  }
2913
2918
  }
@@ -2950,18 +2955,17 @@ static void set_pollset_set(grpc_transport* gt, grpc_stream* /*gs*/,
2950
2955
  static void post_benign_reclaimer(grpc_chttp2_transport* t) {
2951
2956
  if (!t->benign_reclaimer_registered) {
2952
2957
  t->benign_reclaimer_registered = true;
2953
- GRPC_CHTTP2_REF_TRANSPORT(t, "benign_reclaimer");
2954
2958
  t->memory_owner.PostReclaimer(
2955
2959
  grpc_core::ReclamationPass::kBenign,
2956
- [t](absl::optional<grpc_core::ReclamationSweep> sweep) {
2960
+ [t = t->Ref()](
2961
+ absl::optional<grpc_core::ReclamationSweep> sweep) mutable {
2957
2962
  if (sweep.has_value()) {
2958
- GRPC_CLOSURE_INIT(&t->benign_reclaimer_locked,
2959
- benign_reclaimer_locked, t,
2960
- grpc_schedule_on_exec_ctx);
2961
- t->active_reclamation = std::move(*sweep);
2962
- t->combiner->Run(&t->benign_reclaimer_locked, absl::OkStatus());
2963
- } else {
2964
- GRPC_CHTTP2_UNREF_TRANSPORT(t, "benign_reclaimer");
2963
+ auto* tp = t.get();
2964
+ tp->active_reclamation = std::move(*sweep);
2965
+ tp->combiner->Run(
2966
+ grpc_core::InitTransportClosure<benign_reclaimer_locked>(
2967
+ std::move(t), &tp->benign_reclaimer_locked),
2968
+ absl::OkStatus());
2965
2969
  }
2966
2970
  });
2967
2971
  }
@@ -2970,26 +2974,25 @@ static void post_benign_reclaimer(grpc_chttp2_transport* t) {
2970
2974
  static void post_destructive_reclaimer(grpc_chttp2_transport* t) {
2971
2975
  if (!t->destructive_reclaimer_registered) {
2972
2976
  t->destructive_reclaimer_registered = true;
2973
- GRPC_CHTTP2_REF_TRANSPORT(t, "destructive_reclaimer");
2974
2977
  t->memory_owner.PostReclaimer(
2975
2978
  grpc_core::ReclamationPass::kDestructive,
2976
- [t](absl::optional<grpc_core::ReclamationSweep> sweep) {
2979
+ [t = t->Ref()](
2980
+ absl::optional<grpc_core::ReclamationSweep> sweep) mutable {
2977
2981
  if (sweep.has_value()) {
2978
- GRPC_CLOSURE_INIT(&t->destructive_reclaimer_locked,
2979
- destructive_reclaimer_locked, t,
2980
- grpc_schedule_on_exec_ctx);
2981
- t->active_reclamation = std::move(*sweep);
2982
- t->combiner->Run(&t->destructive_reclaimer_locked,
2983
- absl::OkStatus());
2984
- } else {
2985
- GRPC_CHTTP2_UNREF_TRANSPORT(t, "destructive_reclaimer");
2982
+ auto* tp = t.get();
2983
+ tp->active_reclamation = std::move(*sweep);
2984
+ tp->combiner->Run(
2985
+ grpc_core::InitTransportClosure<destructive_reclaimer_locked>(
2986
+ std::move(t), &tp->destructive_reclaimer_locked),
2987
+ absl::OkStatus());
2986
2988
  }
2987
2989
  });
2988
2990
  }
2989
2991
  }
2990
2992
 
2991
- static void benign_reclaimer_locked(void* arg, grpc_error_handle error) {
2992
- grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(arg);
2993
+ static void benign_reclaimer_locked(
2994
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t,
2995
+ grpc_error_handle error) {
2993
2996
  if (error.ok() && t->stream_map.empty()) {
2994
2997
  // Channel with no active streams: send a goaway to try and make it
2995
2998
  // disconnect cleanly
@@ -2997,7 +3000,7 @@ static void benign_reclaimer_locked(void* arg, grpc_error_handle error) {
2997
3000
  gpr_log(GPR_INFO, "HTTP2: %s - send goaway to free memory",
2998
3001
  std::string(t->peer_string.as_string_view()).c_str());
2999
3002
  }
3000
- send_goaway(t,
3003
+ send_goaway(t.get(),
3001
3004
  grpc_error_set_int(GRPC_ERROR_CREATE("Buffers full"),
3002
3005
  grpc_core::StatusIntProperty::kHttp2Error,
3003
3006
  GRPC_HTTP2_ENHANCE_YOUR_CALM),
@@ -3013,11 +3016,11 @@ static void benign_reclaimer_locked(void* arg, grpc_error_handle error) {
3013
3016
  if (error != absl::CancelledError()) {
3014
3017
  t->active_reclamation.Finish();
3015
3018
  }
3016
- GRPC_CHTTP2_UNREF_TRANSPORT(t, "benign_reclaimer");
3017
3019
  }
3018
3020
 
3019
- static void destructive_reclaimer_locked(void* arg, grpc_error_handle error) {
3020
- grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(arg);
3021
+ static void destructive_reclaimer_locked(
3022
+ grpc_core::RefCountedPtr<grpc_chttp2_transport> t,
3023
+ grpc_error_handle error) {
3021
3024
  t->destructive_reclaimer_registered = false;
3022
3025
  if (error.ok() && !t->stream_map.empty()) {
3023
3026
  // As stream_map is a hash map, this selects effectively a random stream.
@@ -3027,7 +3030,7 @@ static void destructive_reclaimer_locked(void* arg, grpc_error_handle error) {
3027
3030
  std::string(t->peer_string.as_string_view()).c_str(), s->id);
3028
3031
  }
3029
3032
  grpc_chttp2_cancel_stream(
3030
- t, s,
3033
+ t.get(), s,
3031
3034
  grpc_error_set_int(GRPC_ERROR_CREATE("Buffers full"),
3032
3035
  grpc_core::StatusIntProperty::kHttp2Error,
3033
3036
  GRPC_HTTP2_ENHANCE_YOUR_CALM));
@@ -3036,13 +3039,12 @@ static void destructive_reclaimer_locked(void* arg, grpc_error_handle error) {
3036
3039
  // there are more streams left, we can immediately post a new
3037
3040
  // reclaimer in case the resource quota needs to free more
3038
3041
  // memory
3039
- post_destructive_reclaimer(t);
3042
+ post_destructive_reclaimer(t.get());
3040
3043
  }
3041
3044
  }
3042
3045
  if (error != absl::CancelledError()) {
3043
3046
  t->active_reclamation.Finish();
3044
3047
  }
3045
- GRPC_CHTTP2_UNREF_TRANSPORT(t, "destructive_reclaimer");
3046
3048
  }
3047
3049
 
3048
3050
  //
@@ -3136,17 +3138,15 @@ grpc_transport* grpc_create_chttp2_transport(
3136
3138
  void grpc_chttp2_transport_start_reading(
3137
3139
  grpc_transport* transport, grpc_slice_buffer* read_buffer,
3138
3140
  grpc_closure* notify_on_receive_settings, grpc_closure* notify_on_close) {
3139
- grpc_chttp2_transport* t =
3140
- reinterpret_cast<grpc_chttp2_transport*>(transport);
3141
- GRPC_CHTTP2_REF_TRANSPORT(
3142
- t, "reading_action"); // matches unref inside reading_action
3141
+ auto t = reinterpret_cast<grpc_chttp2_transport*>(transport)->Ref();
3143
3142
  if (read_buffer != nullptr) {
3144
3143
  grpc_slice_buffer_move_into(read_buffer, &t->read_buffer);
3145
3144
  gpr_free(read_buffer);
3146
3145
  }
3147
- t->combiner->Run(
3148
- grpc_core::NewClosure([t, notify_on_receive_settings,
3149
- notify_on_close](grpc_error_handle) {
3146
+ auto* tp = t.get();
3147
+ tp->combiner->Run(
3148
+ grpc_core::NewClosure([t = std::move(t), notify_on_receive_settings,
3149
+ notify_on_close](grpc_error_handle) mutable {
3150
3150
  if (!t->closed_with_error.ok()) {
3151
3151
  if (notify_on_receive_settings != nullptr) {
3152
3152
  grpc_core::ExecCtx::Run(DEBUG_LOCATION, notify_on_receive_settings,
@@ -3156,12 +3156,11 @@ void grpc_chttp2_transport_start_reading(
3156
3156
  grpc_core::ExecCtx::Run(DEBUG_LOCATION, notify_on_close,
3157
3157
  t->closed_with_error);
3158
3158
  }
3159
- GRPC_CHTTP2_UNREF_TRANSPORT(t, "reading_action");
3160
3159
  return;
3161
3160
  }
3162
3161
  t->notify_on_receive_settings = notify_on_receive_settings;
3163
3162
  t->notify_on_close = notify_on_close;
3164
- read_action_locked(t, absl::OkStatus());
3163
+ read_action_locked(std::move(t), absl::OkStatus());
3165
3164
  }),
3166
3165
  absl::OkStatus());
3167
3166
  }