grpc 1.22.0 → 1.23.0

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

Potentially problematic release.


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

Files changed (176) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +487 -649
  3. data/include/grpc/grpc_security.h +25 -0
  4. data/include/grpc/impl/codegen/grpc_types.h +11 -2
  5. data/include/grpc/impl/codegen/port_platform.h +12 -0
  6. data/src/core/ext/filters/client_channel/backup_poller.cc +4 -2
  7. data/src/core/ext/filters/client_channel/client_channel.cc +477 -182
  8. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +25 -16
  9. data/src/core/ext/filters/client_channel/client_channel_channelz.h +11 -6
  10. data/src/core/ext/filters/client_channel/connector.h +10 -2
  11. data/src/core/ext/filters/client_channel/health/health_check_client.cc +3 -3
  12. data/src/core/ext/filters/client_channel/http_proxy.cc +9 -10
  13. data/src/core/ext/filters/client_channel/lb_policy.cc +2 -17
  14. data/src/core/ext/filters/client_channel/lb_policy.h +36 -8
  15. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +22 -8
  16. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +86 -52
  17. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h +7 -0
  18. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +73 -72
  19. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +8 -12
  20. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +25 -101
  21. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +5 -5
  22. data/src/core/ext/filters/client_channel/parse_address.cc +29 -26
  23. data/src/core/ext/filters/client_channel/resolver.h +3 -11
  24. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +5 -3
  25. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +405 -82
  26. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +44 -51
  27. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc +0 -1
  28. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +0 -1
  29. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +11 -6
  30. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +130 -65
  31. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +8 -3
  32. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +31 -14
  33. data/src/core/ext/filters/client_channel/resolver_factory.h +4 -0
  34. data/src/core/ext/filters/client_channel/resolver_registry.cc +11 -0
  35. data/src/core/ext/filters/client_channel/resolver_registry.h +3 -0
  36. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +10 -49
  37. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +1 -14
  38. data/src/core/ext/filters/client_channel/retry_throttle.h +2 -3
  39. data/src/core/ext/filters/client_channel/subchannel.cc +65 -58
  40. data/src/core/ext/filters/client_channel/subchannel.h +65 -45
  41. data/src/core/ext/filters/client_channel/subchannel_interface.h +15 -30
  42. data/src/core/ext/filters/client_idle/client_idle_filter.cc +262 -0
  43. data/src/core/ext/filters/http/client/http_client_filter.cc +4 -5
  44. data/src/core/ext/filters/http/client_authority_filter.cc +2 -2
  45. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +140 -152
  46. data/src/core/ext/filters/max_age/max_age_filter.cc +3 -3
  47. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +3 -4
  48. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +7 -6
  49. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +63 -38
  50. data/src/core/ext/transport/chttp2/transport/context_list.cc +3 -1
  51. data/src/core/ext/transport/chttp2/transport/frame_data.cc +4 -4
  52. data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +1 -1
  53. data/src/core/ext/transport/chttp2/transport/frame_ping.cc +1 -0
  54. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +8 -0
  55. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +7 -0
  56. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +1 -0
  57. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +37 -22
  58. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +136 -81
  59. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +8 -0
  60. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +7 -166
  61. data/src/core/ext/transport/chttp2/transport/hpack_table.h +41 -15
  62. data/src/core/ext/transport/chttp2/transport/internal.h +13 -2
  63. data/src/core/ext/transport/chttp2/transport/parsing.cc +35 -22
  64. data/src/core/ext/transport/chttp2/transport/stream_map.cc +28 -18
  65. data/src/core/ext/transport/chttp2/transport/writing.cc +1 -0
  66. data/src/core/ext/transport/inproc/inproc_transport.cc +1 -1
  67. data/src/core/lib/channel/channelz.cc +80 -33
  68. data/src/core/lib/channel/channelz.h +28 -13
  69. data/src/core/lib/compression/compression.cc +1 -2
  70. data/src/core/lib/compression/compression_args.cc +13 -6
  71. data/src/core/lib/compression/compression_args.h +3 -2
  72. data/src/core/lib/compression/compression_internal.cc +1 -1
  73. data/src/core/lib/gpr/env_linux.cc +10 -21
  74. data/src/core/lib/gpr/env_posix.cc +0 -5
  75. data/src/core/lib/gpr/string.cc +7 -2
  76. data/src/core/lib/gpr/string.h +1 -0
  77. data/src/core/lib/gpr/sync_posix.cc +0 -129
  78. data/src/core/lib/gprpp/debug_location.h +3 -2
  79. data/src/core/lib/gprpp/fork.cc +14 -21
  80. data/src/core/lib/gprpp/fork.h +15 -4
  81. data/src/core/lib/gprpp/host_port.cc +118 -0
  82. data/src/core/lib/{gpr → gprpp}/host_port.h +27 -11
  83. data/src/core/lib/gprpp/map.h +25 -0
  84. data/src/core/lib/gprpp/memory.h +26 -9
  85. data/src/core/lib/gprpp/ref_counted.h +63 -21
  86. data/src/core/lib/gprpp/string_view.h +143 -0
  87. data/src/core/lib/gprpp/thd.h +10 -1
  88. data/src/core/lib/gprpp/thd_posix.cc +25 -0
  89. data/src/core/lib/gprpp/thd_windows.cc +9 -1
  90. data/src/core/lib/http/httpcli_security_connector.cc +3 -1
  91. data/src/core/lib/iomgr/cfstream_handle.cc +6 -1
  92. data/src/core/lib/iomgr/cfstream_handle.h +8 -2
  93. data/src/core/lib/iomgr/combiner.cc +4 -4
  94. data/src/core/lib/iomgr/error.cc +18 -8
  95. data/src/core/lib/iomgr/error.h +2 -0
  96. data/src/core/lib/iomgr/ev_posix.cc +4 -2
  97. data/src/core/lib/iomgr/executor.cc +4 -1
  98. data/src/core/lib/iomgr/executor/mpmcqueue.cc +183 -0
  99. data/src/core/lib/iomgr/executor/mpmcqueue.h +178 -0
  100. data/src/core/lib/iomgr/executor/threadpool.cc +138 -0
  101. data/src/core/lib/iomgr/executor/threadpool.h +153 -0
  102. data/src/core/lib/iomgr/fork_posix.cc +4 -2
  103. data/src/core/lib/iomgr/iocp_windows.cc +2 -2
  104. data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +14 -0
  105. data/src/core/lib/iomgr/iomgr_uv.cc +3 -0
  106. data/src/core/lib/iomgr/lockfree_event.cc +3 -3
  107. data/src/core/lib/iomgr/resolve_address_custom.cc +16 -20
  108. data/src/core/lib/iomgr/resolve_address_posix.cc +8 -10
  109. data/src/core/lib/iomgr/resolve_address_windows.cc +6 -8
  110. data/src/core/lib/iomgr/sockaddr_utils.cc +5 -3
  111. data/src/core/lib/iomgr/socket_utils_common_posix.cc +0 -1
  112. data/src/core/lib/iomgr/socket_windows.h +1 -1
  113. data/src/core/lib/iomgr/tcp_client_cfstream.cc +7 -6
  114. data/src/core/lib/iomgr/tcp_client_custom.cc +1 -0
  115. data/src/core/lib/iomgr/tcp_custom.cc +4 -0
  116. data/src/core/lib/iomgr/tcp_posix.cc +8 -2
  117. data/src/core/lib/iomgr/tcp_server_custom.cc +1 -0
  118. data/src/core/lib/iomgr/tcp_server_windows.cc +1 -1
  119. data/src/core/lib/iomgr/tcp_windows.cc +7 -7
  120. data/src/core/lib/iomgr/timer_custom.cc +1 -0
  121. data/src/core/lib/iomgr/timer_manager.cc +0 -29
  122. data/src/core/lib/security/credentials/credentials.cc +84 -0
  123. data/src/core/lib/security/credentials/credentials.h +58 -2
  124. data/src/core/lib/security/credentials/jwt/json_token.cc +6 -2
  125. data/src/core/lib/security/credentials/jwt/json_token.h +1 -1
  126. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +245 -24
  127. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +16 -0
  128. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +3 -2
  129. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +21 -25
  130. data/src/core/lib/security/security_connector/local/local_security_connector.cc +3 -2
  131. data/src/core/lib/security/security_connector/security_connector.cc +1 -1
  132. data/src/core/lib/security/security_connector/security_connector.h +1 -1
  133. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +19 -19
  134. data/src/core/lib/security/security_connector/ssl_utils.cc +26 -31
  135. data/src/core/lib/security/security_connector/ssl_utils.h +11 -8
  136. data/src/core/lib/security/security_connector/tls/spiffe_security_connector.cc +16 -20
  137. data/src/core/lib/security/security_connector/tls/spiffe_security_connector.h +4 -3
  138. data/src/core/lib/security/transport/client_auth_filter.cc +1 -2
  139. data/src/core/lib/security/util/json_util.cc +19 -5
  140. data/src/core/lib/security/util/json_util.h +3 -1
  141. data/src/core/lib/slice/slice.cc +69 -50
  142. data/src/core/lib/slice/slice_buffer.cc +6 -5
  143. data/src/core/lib/slice/slice_hash_table.h +3 -7
  144. data/src/core/lib/slice/slice_intern.cc +130 -39
  145. data/src/core/lib/slice/slice_internal.h +8 -0
  146. data/src/core/lib/slice/slice_utils.h +120 -0
  147. data/src/core/lib/slice/slice_weak_hash_table.h +2 -7
  148. data/src/core/lib/surface/call.cc +8 -3
  149. data/src/core/lib/surface/channel.cc +31 -8
  150. data/src/core/lib/surface/completion_queue.cc +17 -7
  151. data/src/core/lib/surface/init_secure.cc +4 -1
  152. data/src/core/lib/surface/lame_client.cc +2 -2
  153. data/src/core/lib/surface/server.cc +34 -35
  154. data/src/core/lib/surface/server.h +8 -17
  155. data/src/core/lib/surface/version.cc +1 -1
  156. data/src/core/lib/transport/byte_stream.cc +3 -5
  157. data/src/core/lib/transport/byte_stream.h +1 -2
  158. data/src/core/lib/transport/error_utils.cc +10 -1
  159. data/src/core/lib/transport/metadata.cc +202 -35
  160. data/src/core/lib/transport/metadata.h +81 -6
  161. data/src/core/lib/transport/static_metadata.cc +1257 -465
  162. data/src/core/lib/transport/static_metadata.h +190 -347
  163. data/src/core/lib/transport/timeout_encoding.cc +7 -0
  164. data/src/core/lib/transport/timeout_encoding.h +3 -2
  165. data/src/core/plugin_registry/grpc_plugin_registry.cc +4 -0
  166. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +0 -1
  167. data/src/core/tsi/ssl/session_cache/ssl_session_cache.h +2 -7
  168. data/src/core/tsi/ssl_transport_security.cc +35 -43
  169. data/src/core/tsi/ssl_transport_security.h +2 -1
  170. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
  171. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +3 -0
  172. data/src/ruby/lib/grpc/generic/rpc_server.rb +1 -1
  173. data/src/ruby/lib/grpc/grpc.rb +1 -1
  174. data/src/ruby/lib/grpc/version.rb +1 -1
  175. metadata +39 -33
  176. data/src/core/lib/gpr/host_port.cc +0 -98
@@ -35,8 +35,8 @@
35
35
  #include <address_sorting/address_sorting.h>
36
36
  #include "src/core/ext/filters/client_channel/parse_address.h"
37
37
  #include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h"
38
- #include "src/core/lib/gpr/host_port.h"
39
38
  #include "src/core/lib/gpr/string.h"
39
+ #include "src/core/lib/gprpp/host_port.h"
40
40
  #include "src/core/lib/iomgr/combiner.h"
41
41
  #include "src/core/lib/iomgr/error.h"
42
42
  #include "src/core/lib/iomgr/executor.h"
@@ -355,9 +355,9 @@ void grpc_dns_lookup_ares_continue_after_check_localhost_and_ip_literals_locked(
355
355
  grpc_ares_hostbyname_request* hr = nullptr;
356
356
  ares_channel* channel = nullptr;
357
357
  /* parse name, splitting it into host and port parts */
358
- char* host;
359
- char* port;
360
- gpr_split_host_port(name, &host, &port);
358
+ grpc_core::UniquePtr<char> host;
359
+ grpc_core::UniquePtr<char> port;
360
+ grpc_core::SplitHostPort(name, &host, &port);
361
361
  if (host == nullptr) {
362
362
  error = grpc_error_set_str(
363
363
  GRPC_ERROR_CREATE_FROM_STATIC_STRING("unparseable host:port"),
@@ -370,7 +370,7 @@ void grpc_dns_lookup_ares_continue_after_check_localhost_and_ip_literals_locked(
370
370
  GRPC_ERROR_STR_TARGET_ADDRESS, grpc_slice_from_copied_string(name));
371
371
  goto error_cleanup;
372
372
  }
373
- port = gpr_strdup(default_port);
373
+ port.reset(gpr_strdup(default_port));
374
374
  }
375
375
  error = grpc_ares_ev_driver_create_locked(&r->ev_driver, interested_parties,
376
376
  query_timeout_ms, combiner, r);
@@ -414,20 +414,22 @@ void grpc_dns_lookup_ares_continue_after_check_localhost_and_ip_literals_locked(
414
414
  }
415
415
  r->pending_queries = 1;
416
416
  if (grpc_ares_query_ipv6()) {
417
- hr = create_hostbyname_request_locked(r, host, grpc_strhtons(port),
418
- false /* is_balancer */);
417
+ hr = create_hostbyname_request_locked(r, host.get(),
418
+ grpc_strhtons(port.get()),
419
+ /*is_balancer=*/false);
419
420
  ares_gethostbyname(*channel, hr->host, AF_INET6, on_hostbyname_done_locked,
420
421
  hr);
421
422
  }
422
- hr = create_hostbyname_request_locked(r, host, grpc_strhtons(port),
423
- false /* is_balancer */);
423
+ hr =
424
+ create_hostbyname_request_locked(r, host.get(), grpc_strhtons(port.get()),
425
+ /*is_balancer=*/false);
424
426
  ares_gethostbyname(*channel, hr->host, AF_INET, on_hostbyname_done_locked,
425
427
  hr);
426
428
  if (check_grpclb) {
427
429
  /* Query the SRV record */
428
430
  grpc_ares_request_ref_locked(r);
429
431
  char* service_name;
430
- gpr_asprintf(&service_name, "_grpclb._tcp.%s", host);
432
+ gpr_asprintf(&service_name, "_grpclb._tcp.%s", host.get());
431
433
  ares_query(*channel, service_name, ns_c_in, ns_t_srv,
432
434
  on_srv_query_done_locked, r);
433
435
  gpr_free(service_name);
@@ -435,28 +437,25 @@ void grpc_dns_lookup_ares_continue_after_check_localhost_and_ip_literals_locked(
435
437
  if (r->service_config_json_out != nullptr) {
436
438
  grpc_ares_request_ref_locked(r);
437
439
  char* config_name;
438
- gpr_asprintf(&config_name, "_grpc_config.%s", host);
440
+ gpr_asprintf(&config_name, "_grpc_config.%s", host.get());
439
441
  ares_search(*channel, config_name, ns_c_in, ns_t_txt, on_txt_done_locked,
440
442
  r);
441
443
  gpr_free(config_name);
442
444
  }
443
445
  grpc_ares_ev_driver_start_locked(r->ev_driver);
444
446
  grpc_ares_request_unref_locked(r);
445
- gpr_free(host);
446
- gpr_free(port);
447
447
  return;
448
448
 
449
449
  error_cleanup:
450
450
  GRPC_CLOSURE_SCHED(r->on_done, error);
451
- gpr_free(host);
452
- gpr_free(port);
453
451
  }
454
452
 
455
453
  static bool inner_resolve_as_ip_literal_locked(
456
454
  const char* name, const char* default_port,
457
- grpc_core::UniquePtr<grpc_core::ServerAddressList>* addrs, char** host,
458
- char** port, char** hostport) {
459
- gpr_split_host_port(name, host, port);
455
+ grpc_core::UniquePtr<grpc_core::ServerAddressList>* addrs,
456
+ grpc_core::UniquePtr<char>* host, grpc_core::UniquePtr<char>* port,
457
+ grpc_core::UniquePtr<char>* hostport) {
458
+ grpc_core::SplitHostPort(name, host, port);
460
459
  if (*host == nullptr) {
461
460
  gpr_log(GPR_ERROR,
462
461
  "Failed to parse %s to host:port while attempting to resolve as ip "
@@ -472,12 +471,14 @@ static bool inner_resolve_as_ip_literal_locked(
472
471
  name);
473
472
  return false;
474
473
  }
475
- *port = gpr_strdup(default_port);
474
+ port->reset(gpr_strdup(default_port));
476
475
  }
477
476
  grpc_resolved_address addr;
478
- GPR_ASSERT(gpr_join_host_port(hostport, *host, atoi(*port)));
479
- if (grpc_parse_ipv4_hostport(*hostport, &addr, false /* log errors */) ||
480
- grpc_parse_ipv6_hostport(*hostport, &addr, false /* log errors */)) {
477
+ GPR_ASSERT(grpc_core::JoinHostPort(hostport, host->get(), atoi(port->get())));
478
+ if (grpc_parse_ipv4_hostport(hostport->get(), &addr,
479
+ false /* log errors */) ||
480
+ grpc_parse_ipv6_hostport(hostport->get(), &addr,
481
+ false /* log errors */)) {
481
482
  GPR_ASSERT(*addrs == nullptr);
482
483
  *addrs = grpc_core::MakeUnique<ServerAddressList>();
483
484
  (*addrs)->emplace_back(addr.addr, addr.len, nullptr /* args */);
@@ -489,24 +490,22 @@ static bool inner_resolve_as_ip_literal_locked(
489
490
  static bool resolve_as_ip_literal_locked(
490
491
  const char* name, const char* default_port,
491
492
  grpc_core::UniquePtr<grpc_core::ServerAddressList>* addrs) {
492
- char* host = nullptr;
493
- char* port = nullptr;
494
- char* hostport = nullptr;
493
+ grpc_core::UniquePtr<char> host;
494
+ grpc_core::UniquePtr<char> port;
495
+ grpc_core::UniquePtr<char> hostport;
495
496
  bool out = inner_resolve_as_ip_literal_locked(name, default_port, addrs,
496
497
  &host, &port, &hostport);
497
- gpr_free(host);
498
- gpr_free(port);
499
- gpr_free(hostport);
500
498
  return out;
501
499
  }
502
500
 
503
- static bool target_matches_localhost_inner(const char* name, char** host,
504
- char** port) {
505
- if (!gpr_split_host_port(name, host, port)) {
501
+ static bool target_matches_localhost_inner(const char* name,
502
+ grpc_core::UniquePtr<char>* host,
503
+ grpc_core::UniquePtr<char>* port) {
504
+ if (!grpc_core::SplitHostPort(name, host, port)) {
506
505
  gpr_log(GPR_ERROR, "Unable to split host and port for name: %s", name);
507
506
  return false;
508
507
  }
509
- if (gpr_stricmp(*host, "localhost") == 0) {
508
+ if (gpr_stricmp(host->get(), "localhost") == 0) {
510
509
  return true;
511
510
  } else {
512
511
  return false;
@@ -514,20 +513,17 @@ static bool target_matches_localhost_inner(const char* name, char** host,
514
513
  }
515
514
 
516
515
  static bool target_matches_localhost(const char* name) {
517
- char* host = nullptr;
518
- char* port = nullptr;
519
- bool out = target_matches_localhost_inner(name, &host, &port);
520
- gpr_free(host);
521
- gpr_free(port);
522
- return out;
516
+ grpc_core::UniquePtr<char> host;
517
+ grpc_core::UniquePtr<char> port;
518
+ return target_matches_localhost_inner(name, &host, &port);
523
519
  }
524
520
 
525
521
  #ifdef GRPC_ARES_RESOLVE_LOCALHOST_MANUALLY
526
522
  static bool inner_maybe_resolve_localhost_manually_locked(
527
523
  const char* name, const char* default_port,
528
- grpc_core::UniquePtr<grpc_core::ServerAddressList>* addrs, char** host,
529
- char** port) {
530
- gpr_split_host_port(name, host, port);
524
+ grpc_core::UniquePtr<grpc_core::ServerAddressList>* addrs,
525
+ grpc_core::UniquePtr<char>* host, grpc_core::UniquePtr<char>* port) {
526
+ grpc_core::SplitHostPort(name, host, port);
531
527
  if (*host == nullptr) {
532
528
  gpr_log(GPR_ERROR,
533
529
  "Failed to parse %s into host:port during manual localhost "
@@ -543,12 +539,12 @@ static bool inner_maybe_resolve_localhost_manually_locked(
543
539
  name);
544
540
  return false;
545
541
  }
546
- *port = gpr_strdup(default_port);
542
+ port->reset(gpr_strdup(default_port));
547
543
  }
548
- if (gpr_stricmp(*host, "localhost") == 0) {
544
+ if (gpr_stricmp(host->get(), "localhost") == 0) {
549
545
  GPR_ASSERT(*addrs == nullptr);
550
546
  *addrs = grpc_core::MakeUnique<grpc_core::ServerAddressList>();
551
- uint16_t numeric_port = grpc_strhtons(*port);
547
+ uint16_t numeric_port = grpc_strhtons(port->get());
552
548
  // Append the ipv6 loopback address.
553
549
  struct sockaddr_in6 ipv6_loopback_addr;
554
550
  memset(&ipv6_loopback_addr, 0, sizeof(ipv6_loopback_addr));
@@ -576,13 +572,10 @@ static bool inner_maybe_resolve_localhost_manually_locked(
576
572
  static bool grpc_ares_maybe_resolve_localhost_manually_locked(
577
573
  const char* name, const char* default_port,
578
574
  grpc_core::UniquePtr<grpc_core::ServerAddressList>* addrs) {
579
- char* host = nullptr;
580
- char* port = nullptr;
581
- bool out = inner_maybe_resolve_localhost_manually_locked(name, default_port,
582
- addrs, &host, &port);
583
- gpr_free(host);
584
- gpr_free(port);
585
- return out;
575
+ grpc_core::UniquePtr<char> host;
576
+ grpc_core::UniquePtr<char> port;
577
+ return inner_maybe_resolve_localhost_manually_locked(name, default_port,
578
+ addrs, &host, &port);
586
579
  }
587
580
  #else /* GRPC_ARES_RESOLVE_LOCALHOST_MANUALLY */
588
581
  static bool grpc_ares_maybe_resolve_localhost_manually_locked(
@@ -26,7 +26,6 @@
26
26
  #include "src/core/ext/filters/client_channel/parse_address.h"
27
27
  #include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h"
28
28
  #include "src/core/ext/filters/client_channel/server_address.h"
29
- #include "src/core/lib/gpr/host_port.h"
30
29
  #include "src/core/lib/gpr/string.h"
31
30
 
32
31
  bool grpc_ares_query_ipv6() {
@@ -26,7 +26,6 @@
26
26
  #include "src/core/ext/filters/client_channel/parse_address.h"
27
27
  #include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h"
28
28
  #include "src/core/ext/filters/client_channel/server_address.h"
29
- #include "src/core/lib/gpr/host_port.h"
30
29
  #include "src/core/lib/gpr/string.h"
31
30
  #include "src/core/lib/iomgr/socket_windows.h"
32
31
 
@@ -31,7 +31,6 @@
31
31
  #include "src/core/ext/filters/client_channel/server_address.h"
32
32
  #include "src/core/lib/backoff/backoff.h"
33
33
  #include "src/core/lib/channel/channel_args.h"
34
- #include "src/core/lib/gpr/host_port.h"
35
34
  #include "src/core/lib/gpr/string.h"
36
35
  #include "src/core/lib/gprpp/manual_constructor.h"
37
36
  #include "src/core/lib/iomgr/combiner.h"
@@ -111,7 +110,7 @@ NativeDnsResolver::NativeDnsResolver(ResolverArgs args)
111
110
  const grpc_arg* arg = grpc_channel_args_find(
112
111
  args.args, GRPC_ARG_DNS_MIN_TIME_BETWEEN_RESOLUTIONS_MS);
113
112
  min_time_between_resolutions_ =
114
- grpc_channel_arg_get_integer(arg, {1000, 0, INT_MAX});
113
+ grpc_channel_arg_get_integer(arg, {1000 * 30, 0, INT_MAX});
115
114
  interested_parties_ = grpc_pollset_set_create();
116
115
  if (args.pollset_set != nullptr) {
117
116
  grpc_pollset_set_add_pollset_set(interested_parties_, args.pollset_set);
@@ -230,7 +229,8 @@ void NativeDnsResolver::MaybeStartResolvingLocked() {
230
229
  // new closure API is done, find a way to track this ref with the timer
231
230
  // callback as part of the type system.
232
231
  Ref(DEBUG_LOCATION, "next_resolution_timer_cooldown").release();
233
- grpc_timer_init(&next_resolution_timer_, ms_until_next_resolution,
232
+ grpc_timer_init(&next_resolution_timer_,
233
+ ExecCtx::Get()->Now() + ms_until_next_resolution,
234
234
  &on_next_resolution_);
235
235
  return;
236
236
  }
@@ -258,11 +258,16 @@ void NativeDnsResolver::StartResolvingLocked() {
258
258
 
259
259
  class NativeDnsResolverFactory : public ResolverFactory {
260
260
  public:
261
- OrphanablePtr<Resolver> CreateResolver(ResolverArgs args) const override {
262
- if (GPR_UNLIKELY(0 != strcmp(args.uri->authority, ""))) {
261
+ bool IsValidUri(const grpc_uri* uri) const override {
262
+ if (GPR_UNLIKELY(0 != strcmp(uri->authority, ""))) {
263
263
  gpr_log(GPR_ERROR, "authority based dns uri's not supported");
264
- return OrphanablePtr<Resolver>(nullptr);
264
+ return false;
265
265
  }
266
+ return true;
267
+ }
268
+
269
+ OrphanablePtr<Resolver> CreateResolver(ResolverArgs args) const override {
270
+ if (!IsValidUri(args.uri)) return nullptr;
266
271
  return OrphanablePtr<Resolver>(New<NativeDnsResolver>(std::move(args)));
267
272
  }
268
273
 
@@ -32,7 +32,6 @@
32
32
  #include "src/core/ext/filters/client_channel/resolver_registry.h"
33
33
  #include "src/core/ext/filters/client_channel/server_address.h"
34
34
  #include "src/core/lib/channel/channel_args.h"
35
- #include "src/core/lib/gpr/host_port.h"
36
35
  #include "src/core/lib/gpr/string.h"
37
36
  #include "src/core/lib/gpr/useful.h"
38
37
  #include "src/core/lib/iomgr/closure.h"
@@ -61,7 +60,13 @@ class FakeResolver : public Resolver {
61
60
 
62
61
  virtual ~FakeResolver();
63
62
 
64
- void ShutdownLocked() override { active_ = false; }
63
+ void ShutdownLocked() override {
64
+ shutdown_ = true;
65
+ if (response_generator_ != nullptr) {
66
+ response_generator_->SetFakeResolver(nullptr);
67
+ response_generator_.reset();
68
+ }
69
+ }
65
70
 
66
71
  void MaybeSendResultLocked();
67
72
 
@@ -69,6 +74,7 @@ class FakeResolver : public Resolver {
69
74
 
70
75
  // passed-in parameters
71
76
  grpc_channel_args* channel_args_ = nullptr;
77
+ RefCountedPtr<FakeResolverResponseGenerator> response_generator_;
72
78
  // If has_next_result_ is true, next_result_ is the next resolution result
73
79
  // to be returned.
74
80
  bool has_next_result_ = false;
@@ -77,8 +83,10 @@ class FakeResolver : public Resolver {
77
83
  // RequestReresolutionLocked().
78
84
  bool has_reresolution_result_ = false;
79
85
  Result reresolution_result_;
80
- // True between the calls to StartLocked() ShutdownLocked().
81
- bool active_ = false;
86
+ // True after the call to StartLocked().
87
+ bool started_ = false;
88
+ // True after the call to ShutdownLocked().
89
+ bool shutdown_ = false;
82
90
  // if true, return failure
83
91
  bool return_failure_ = false;
84
92
  // pending re-resolution
@@ -87,25 +95,27 @@ class FakeResolver : public Resolver {
87
95
  };
88
96
 
89
97
  FakeResolver::FakeResolver(ResolverArgs args)
90
- : Resolver(args.combiner, std::move(args.result_handler)) {
98
+ : Resolver(args.combiner, std::move(args.result_handler)),
99
+ response_generator_(
100
+ FakeResolverResponseGenerator::GetFromArgs(args.args)) {
91
101
  GRPC_CLOSURE_INIT(&reresolution_closure_, ReturnReresolutionResult, this,
92
102
  grpc_combiner_scheduler(combiner()));
93
- channel_args_ = grpc_channel_args_copy(args.args);
94
- FakeResolverResponseGenerator* response_generator =
95
- FakeResolverResponseGenerator::GetFromArgs(args.args);
96
- if (response_generator != nullptr) {
97
- response_generator->resolver_ = this;
98
- if (response_generator->has_result_) {
99
- response_generator->SetResponse(std::move(response_generator->result_));
100
- response_generator->has_result_ = false;
101
- }
103
+ // Channels sharing the same subchannels may have different resolver response
104
+ // generators. If we don't remove this arg, subchannel pool will create new
105
+ // subchannels for the same address instead of reusing existing ones because
106
+ // of different values of this channel arg.
107
+ const char* args_to_remove[] = {GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR};
108
+ channel_args_ = grpc_channel_args_copy_and_remove(
109
+ args.args, args_to_remove, GPR_ARRAY_SIZE(args_to_remove));
110
+ if (response_generator_ != nullptr) {
111
+ response_generator_->SetFakeResolver(Ref());
102
112
  }
103
113
  }
104
114
 
105
115
  FakeResolver::~FakeResolver() { grpc_channel_args_destroy(channel_args_); }
106
116
 
107
117
  void FakeResolver::StartLocked() {
108
- active_ = true;
118
+ started_ = true;
109
119
  MaybeSendResultLocked();
110
120
  }
111
121
 
@@ -125,7 +135,7 @@ void FakeResolver::RequestReresolutionLocked() {
125
135
  }
126
136
 
127
137
  void FakeResolver::MaybeSendResultLocked() {
128
- if (!active_) return;
138
+ if (!started_ || shutdown_) return;
129
139
  if (return_failure_) {
130
140
  // TODO(roth): Change resolver result generator to be able to inject
131
141
  // the error to be returned.
@@ -160,9 +170,13 @@ void FakeResolver::ReturnReresolutionResult(void* arg, grpc_error* error) {
160
170
  // FakeResolverResponseGenerator
161
171
  //
162
172
 
173
+ FakeResolverResponseGenerator::FakeResolverResponseGenerator() {}
174
+
175
+ FakeResolverResponseGenerator::~FakeResolverResponseGenerator() {}
176
+
163
177
  struct SetResponseClosureArg {
164
178
  grpc_closure set_response_closure;
165
- FakeResolverResponseGenerator* generator;
179
+ RefCountedPtr<FakeResolver> resolver;
166
180
  Resolver::Result result;
167
181
  bool has_result = false;
168
182
  bool immediate = true;
@@ -171,98 +185,146 @@ struct SetResponseClosureArg {
171
185
  void FakeResolverResponseGenerator::SetResponseLocked(void* arg,
172
186
  grpc_error* error) {
173
187
  SetResponseClosureArg* closure_arg = static_cast<SetResponseClosureArg*>(arg);
174
- FakeResolver* resolver = closure_arg->generator->resolver_;
175
- resolver->next_result_ = std::move(closure_arg->result);
176
- resolver->has_next_result_ = true;
177
- resolver->MaybeSendResultLocked();
178
- closure_arg->generator->Unref();
188
+ auto& resolver = closure_arg->resolver;
189
+ if (!resolver->shutdown_) {
190
+ resolver->next_result_ = std::move(closure_arg->result);
191
+ resolver->has_next_result_ = true;
192
+ resolver->MaybeSendResultLocked();
193
+ }
179
194
  Delete(closure_arg);
180
195
  }
181
196
 
182
197
  void FakeResolverResponseGenerator::SetResponse(Resolver::Result result) {
183
- if (resolver_ != nullptr) {
184
- Ref().release(); // ref to be held by closure
185
- SetResponseClosureArg* closure_arg = New<SetResponseClosureArg>();
186
- closure_arg->generator = this;
187
- closure_arg->result = std::move(result);
188
- GRPC_CLOSURE_SCHED(
189
- GRPC_CLOSURE_INIT(&closure_arg->set_response_closure, SetResponseLocked,
190
- closure_arg,
191
- grpc_combiner_scheduler(resolver_->combiner())),
192
- GRPC_ERROR_NONE);
193
- } else {
194
- GPR_ASSERT(!has_result_);
195
- has_result_ = true;
196
- result_ = std::move(result);
198
+ RefCountedPtr<FakeResolver> resolver;
199
+ {
200
+ MutexLock lock(&mu_);
201
+ if (resolver_ == nullptr) {
202
+ has_result_ = true;
203
+ result_ = std::move(result);
204
+ return;
205
+ }
206
+ resolver = resolver_->Ref();
197
207
  }
208
+ SetResponseClosureArg* closure_arg = New<SetResponseClosureArg>();
209
+ closure_arg->resolver = std::move(resolver);
210
+ closure_arg->result = std::move(result);
211
+ GRPC_CLOSURE_SCHED(
212
+ GRPC_CLOSURE_INIT(
213
+ &closure_arg->set_response_closure, SetResponseLocked, closure_arg,
214
+ grpc_combiner_scheduler(closure_arg->resolver->combiner())),
215
+ GRPC_ERROR_NONE);
198
216
  }
199
217
 
200
218
  void FakeResolverResponseGenerator::SetReresolutionResponseLocked(
201
219
  void* arg, grpc_error* error) {
202
220
  SetResponseClosureArg* closure_arg = static_cast<SetResponseClosureArg*>(arg);
203
- FakeResolver* resolver = closure_arg->generator->resolver_;
204
- resolver->reresolution_result_ = std::move(closure_arg->result);
205
- resolver->has_reresolution_result_ = closure_arg->has_result;
221
+ auto& resolver = closure_arg->resolver;
222
+ if (!resolver->shutdown_) {
223
+ resolver->reresolution_result_ = std::move(closure_arg->result);
224
+ resolver->has_reresolution_result_ = closure_arg->has_result;
225
+ }
206
226
  Delete(closure_arg);
207
227
  }
208
228
 
209
229
  void FakeResolverResponseGenerator::SetReresolutionResponse(
210
230
  Resolver::Result result) {
211
- GPR_ASSERT(resolver_ != nullptr);
231
+ RefCountedPtr<FakeResolver> resolver;
232
+ {
233
+ MutexLock lock(&mu_);
234
+ GPR_ASSERT(resolver_ != nullptr);
235
+ resolver = resolver_->Ref();
236
+ }
212
237
  SetResponseClosureArg* closure_arg = New<SetResponseClosureArg>();
213
- closure_arg->generator = this;
238
+ closure_arg->resolver = std::move(resolver);
214
239
  closure_arg->result = std::move(result);
215
240
  closure_arg->has_result = true;
216
241
  GRPC_CLOSURE_SCHED(
217
- GRPC_CLOSURE_INIT(&closure_arg->set_response_closure,
218
- SetReresolutionResponseLocked, closure_arg,
219
- grpc_combiner_scheduler(resolver_->combiner())),
242
+ GRPC_CLOSURE_INIT(
243
+ &closure_arg->set_response_closure, SetReresolutionResponseLocked,
244
+ closure_arg,
245
+ grpc_combiner_scheduler(closure_arg->resolver->combiner())),
220
246
  GRPC_ERROR_NONE);
221
247
  }
222
248
 
223
249
  void FakeResolverResponseGenerator::UnsetReresolutionResponse() {
224
- GPR_ASSERT(resolver_ != nullptr);
250
+ RefCountedPtr<FakeResolver> resolver;
251
+ {
252
+ MutexLock lock(&mu_);
253
+ GPR_ASSERT(resolver_ != nullptr);
254
+ resolver = resolver_->Ref();
255
+ }
225
256
  SetResponseClosureArg* closure_arg = New<SetResponseClosureArg>();
226
- closure_arg->generator = this;
257
+ closure_arg->resolver = std::move(resolver);
227
258
  GRPC_CLOSURE_SCHED(
228
- GRPC_CLOSURE_INIT(&closure_arg->set_response_closure,
229
- SetReresolutionResponseLocked, closure_arg,
230
- grpc_combiner_scheduler(resolver_->combiner())),
259
+ GRPC_CLOSURE_INIT(
260
+ &closure_arg->set_response_closure, SetReresolutionResponseLocked,
261
+ closure_arg,
262
+ grpc_combiner_scheduler(closure_arg->resolver->combiner())),
231
263
  GRPC_ERROR_NONE);
232
264
  }
233
265
 
234
266
  void FakeResolverResponseGenerator::SetFailureLocked(void* arg,
235
267
  grpc_error* error) {
236
268
  SetResponseClosureArg* closure_arg = static_cast<SetResponseClosureArg*>(arg);
237
- FakeResolver* resolver = closure_arg->generator->resolver_;
238
- resolver->return_failure_ = true;
239
- if (closure_arg->immediate) resolver->MaybeSendResultLocked();
269
+ auto& resolver = closure_arg->resolver;
270
+ if (!resolver->shutdown_) {
271
+ resolver->return_failure_ = true;
272
+ if (closure_arg->immediate) resolver->MaybeSendResultLocked();
273
+ }
240
274
  Delete(closure_arg);
241
275
  }
242
276
 
243
277
  void FakeResolverResponseGenerator::SetFailure() {
244
- GPR_ASSERT(resolver_ != nullptr);
278
+ RefCountedPtr<FakeResolver> resolver;
279
+ {
280
+ MutexLock lock(&mu_);
281
+ GPR_ASSERT(resolver_ != nullptr);
282
+ resolver = resolver_->Ref();
283
+ }
245
284
  SetResponseClosureArg* closure_arg = New<SetResponseClosureArg>();
246
- closure_arg->generator = this;
285
+ closure_arg->resolver = std::move(resolver);
247
286
  GRPC_CLOSURE_SCHED(
248
- GRPC_CLOSURE_INIT(&closure_arg->set_response_closure, SetFailureLocked,
249
- closure_arg,
250
- grpc_combiner_scheduler(resolver_->combiner())),
287
+ GRPC_CLOSURE_INIT(
288
+ &closure_arg->set_response_closure, SetFailureLocked, closure_arg,
289
+ grpc_combiner_scheduler(closure_arg->resolver->combiner())),
251
290
  GRPC_ERROR_NONE);
252
291
  }
253
292
 
254
293
  void FakeResolverResponseGenerator::SetFailureOnReresolution() {
255
- GPR_ASSERT(resolver_ != nullptr);
294
+ RefCountedPtr<FakeResolver> resolver;
295
+ {
296
+ MutexLock lock(&mu_);
297
+ GPR_ASSERT(resolver_ != nullptr);
298
+ resolver = resolver_->Ref();
299
+ }
256
300
  SetResponseClosureArg* closure_arg = New<SetResponseClosureArg>();
257
- closure_arg->generator = this;
301
+ closure_arg->resolver = std::move(resolver);
258
302
  closure_arg->immediate = false;
259
303
  GRPC_CLOSURE_SCHED(
260
- GRPC_CLOSURE_INIT(&closure_arg->set_response_closure, SetFailureLocked,
261
- closure_arg,
262
- grpc_combiner_scheduler(resolver_->combiner())),
304
+ GRPC_CLOSURE_INIT(
305
+ &closure_arg->set_response_closure, SetFailureLocked, closure_arg,
306
+ grpc_combiner_scheduler(closure_arg->resolver->combiner())),
263
307
  GRPC_ERROR_NONE);
264
308
  }
265
309
 
310
+ void FakeResolverResponseGenerator::SetFakeResolver(
311
+ RefCountedPtr<FakeResolver> resolver) {
312
+ MutexLock lock(&mu_);
313
+ resolver_ = std::move(resolver);
314
+ if (resolver_ == nullptr) return;
315
+ if (has_result_) {
316
+ SetResponseClosureArg* closure_arg = New<SetResponseClosureArg>();
317
+ closure_arg->resolver = resolver_->Ref();
318
+ closure_arg->result = std::move(result_);
319
+ GRPC_CLOSURE_SCHED(
320
+ GRPC_CLOSURE_INIT(&closure_arg->set_response_closure, SetResponseLocked,
321
+ closure_arg,
322
+ grpc_combiner_scheduler(resolver_->combiner())),
323
+ GRPC_ERROR_NONE);
324
+ has_result_ = false;
325
+ }
326
+ }
327
+
266
328
  namespace {
267
329
 
268
330
  static void* response_generator_arg_copy(void* p) {
@@ -300,12 +362,13 @@ grpc_arg FakeResolverResponseGenerator::MakeChannelArg(
300
362
  return arg;
301
363
  }
302
364
 
303
- FakeResolverResponseGenerator* FakeResolverResponseGenerator::GetFromArgs(
304
- const grpc_channel_args* args) {
365
+ RefCountedPtr<FakeResolverResponseGenerator>
366
+ FakeResolverResponseGenerator::GetFromArgs(const grpc_channel_args* args) {
305
367
  const grpc_arg* arg =
306
368
  grpc_channel_args_find(args, GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR);
307
369
  if (arg == nullptr || arg->type != GRPC_ARG_POINTER) return nullptr;
308
- return static_cast<FakeResolverResponseGenerator*>(arg->value.pointer.p);
370
+ return static_cast<FakeResolverResponseGenerator*>(arg->value.pointer.p)
371
+ ->Ref();
309
372
  }
310
373
 
311
374
  //
@@ -316,6 +379,8 @@ namespace {
316
379
 
317
380
  class FakeResolverFactory : public ResolverFactory {
318
381
  public:
382
+ bool IsValidUri(const grpc_uri* uri) const override { return true; }
383
+
319
384
  OrphanablePtr<Resolver> CreateResolver(ResolverArgs args) const override {
320
385
  return OrphanablePtr<Resolver>(New<FakeResolver>(std::move(args)));
321
386
  }