grpc 1.17.1 → 1.18.0.pre1

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 (166) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1228 -988
  3. data/etc/roots.pem +242 -30
  4. data/include/grpc/grpc.h +2 -1
  5. data/include/grpc/grpc_security_constants.h +3 -3
  6. data/include/grpc/impl/codegen/atm_gcc_sync.h +2 -0
  7. data/include/grpc/impl/codegen/atm_windows.h +2 -0
  8. data/include/grpc/impl/codegen/compression_types.h +2 -1
  9. data/include/grpc/impl/codegen/grpc_types.h +1 -1
  10. data/include/grpc/impl/codegen/port_platform.h +9 -0
  11. data/src/core/ext/filters/client_channel/client_channel.cc +163 -882
  12. data/src/core/ext/filters/client_channel/health/health_check_client.cc +2 -4
  13. data/src/core/ext/filters/client_channel/health/health_check_client.h +2 -3
  14. data/src/core/ext/filters/client_channel/lb_policy.cc +1 -1
  15. data/src/core/ext/filters/client_channel/lb_policy.h +8 -17
  16. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +176 -216
  17. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +1 -1
  18. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +20 -23
  19. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +1 -1
  20. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +49 -52
  21. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +13 -35
  22. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +31 -30
  23. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +69 -225
  24. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h +1 -1
  25. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc +20 -23
  26. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h +1 -1
  27. data/src/core/ext/filters/client_channel/lb_policy_factory.h +2 -84
  28. data/src/core/ext/filters/client_channel/request_routing.cc +936 -0
  29. data/src/core/ext/filters/client_channel/request_routing.h +177 -0
  30. data/src/core/ext/filters/client_channel/resolver.cc +1 -1
  31. data/src/core/ext/filters/client_channel/resolver.h +1 -1
  32. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +37 -26
  33. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +30 -18
  34. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +119 -100
  35. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +8 -5
  36. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +5 -4
  37. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc +2 -1
  38. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +12 -14
  39. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +5 -9
  40. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +2 -1
  41. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +1 -2
  42. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +17 -17
  43. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +45 -52
  44. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +13 -17
  45. data/src/core/ext/filters/client_channel/server_address.cc +103 -0
  46. data/src/core/ext/filters/client_channel/server_address.h +108 -0
  47. data/src/core/ext/filters/client_channel/subchannel.cc +10 -8
  48. data/src/core/ext/filters/client_channel/subchannel.h +9 -6
  49. data/src/core/ext/filters/client_channel/subchannel_index.cc +20 -27
  50. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +3 -2
  51. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +8 -9
  52. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +1 -1
  53. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +1 -1
  54. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +8 -11
  55. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +24 -54
  56. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +3 -1
  57. data/src/core/ext/transport/chttp2/transport/context_list.cc +67 -0
  58. data/src/core/ext/transport/chttp2/transport/context_list.h +53 -0
  59. data/src/core/ext/transport/chttp2/transport/internal.h +38 -11
  60. data/src/core/ext/transport/chttp2/transport/writing.cc +5 -0
  61. data/src/core/ext/transport/inproc/inproc_transport.cc +1 -1
  62. data/src/core/lib/channel/channelz.cc +19 -18
  63. data/src/core/lib/channel/channelz.h +7 -1
  64. data/src/core/lib/channel/channelz_registry.cc +3 -2
  65. data/src/core/lib/debug/trace.cc +3 -0
  66. data/src/core/lib/debug/trace.h +5 -3
  67. data/src/core/lib/gpr/sync_posix.cc +96 -4
  68. data/src/core/lib/gprpp/inlined_vector.h +25 -19
  69. data/src/core/lib/gprpp/memory.h +2 -11
  70. data/src/core/lib/gprpp/orphanable.h +18 -82
  71. data/src/core/lib/gprpp/ref_counted.h +75 -84
  72. data/src/core/lib/gprpp/ref_counted_ptr.h +22 -17
  73. data/src/core/lib/http/httpcli_security_connector.cc +101 -94
  74. data/src/core/lib/http/parser.h +5 -5
  75. data/src/core/lib/iomgr/buffer_list.cc +16 -5
  76. data/src/core/lib/iomgr/buffer_list.h +10 -3
  77. data/src/core/lib/iomgr/call_combiner.cc +50 -2
  78. data/src/core/lib/iomgr/call_combiner.h +29 -2
  79. data/src/core/lib/iomgr/dynamic_annotations.h +67 -0
  80. data/src/core/lib/iomgr/endpoint.cc +4 -0
  81. data/src/core/lib/iomgr/endpoint.h +3 -0
  82. data/src/core/lib/iomgr/endpoint_pair_posix.cc +2 -2
  83. data/src/core/lib/iomgr/ev_epoll1_linux.cc +4 -0
  84. data/src/core/lib/iomgr/ev_epollex_linux.cc +4 -0
  85. data/src/core/lib/iomgr/ev_poll_posix.cc +4 -0
  86. data/src/core/lib/iomgr/ev_posix.cc +15 -7
  87. data/src/core/lib/iomgr/ev_posix.h +10 -0
  88. data/src/core/lib/iomgr/exec_ctx.cc +13 -0
  89. data/src/core/lib/iomgr/fork_posix.cc +1 -1
  90. data/src/core/lib/iomgr/internal_errqueue.cc +36 -3
  91. data/src/core/lib/iomgr/internal_errqueue.h +7 -1
  92. data/src/core/lib/iomgr/iomgr.cc +7 -0
  93. data/src/core/lib/iomgr/iomgr.h +4 -0
  94. data/src/core/lib/iomgr/iomgr_custom.cc +3 -1
  95. data/src/core/lib/iomgr/iomgr_internal.cc +4 -0
  96. data/src/core/lib/iomgr/iomgr_internal.h +4 -0
  97. data/src/core/lib/iomgr/iomgr_posix.cc +6 -1
  98. data/src/core/lib/iomgr/iomgr_windows.cc +4 -1
  99. data/src/core/lib/iomgr/port.h +1 -2
  100. data/src/core/lib/iomgr/resource_quota.cc +1 -0
  101. data/src/core/lib/iomgr/sockaddr_utils.cc +1 -0
  102. data/src/core/lib/iomgr/tcp_custom.cc +4 -1
  103. data/src/core/lib/iomgr/tcp_posix.cc +95 -35
  104. data/src/core/lib/iomgr/tcp_windows.cc +4 -1
  105. data/src/core/lib/iomgr/timer_manager.cc +6 -0
  106. data/src/core/lib/security/context/security_context.cc +75 -108
  107. data/src/core/lib/security/context/security_context.h +59 -35
  108. data/src/core/lib/security/credentials/alts/alts_credentials.cc +36 -48
  109. data/src/core/lib/security/credentials/alts/alts_credentials.h +37 -10
  110. data/src/core/lib/security/credentials/composite/composite_credentials.cc +97 -157
  111. data/src/core/lib/security/credentials/composite/composite_credentials.h +60 -24
  112. data/src/core/lib/security/credentials/credentials.cc +18 -142
  113. data/src/core/lib/security/credentials/credentials.h +119 -95
  114. data/src/core/lib/security/credentials/fake/fake_credentials.cc +46 -71
  115. data/src/core/lib/security/credentials/fake/fake_credentials.h +23 -5
  116. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +144 -51
  117. data/src/core/lib/security/credentials/google_default/google_default_credentials.h +28 -5
  118. data/src/core/lib/security/credentials/iam/iam_credentials.cc +27 -35
  119. data/src/core/lib/security/credentials/iam/iam_credentials.h +18 -4
  120. data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +60 -69
  121. data/src/core/lib/security/credentials/jwt/jwt_credentials.h +29 -10
  122. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +2 -0
  123. data/src/core/lib/security/credentials/local/local_credentials.cc +19 -32
  124. data/src/core/lib/security/credentials/local/local_credentials.h +32 -11
  125. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +130 -149
  126. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +74 -29
  127. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +59 -77
  128. data/src/core/lib/security/credentials/plugin/plugin_credentials.h +40 -17
  129. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +66 -83
  130. data/src/core/lib/security/credentials/ssl/ssl_credentials.h +58 -15
  131. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +152 -177
  132. data/src/core/lib/security/security_connector/alts/alts_security_connector.h +12 -10
  133. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +210 -215
  134. data/src/core/lib/security/security_connector/fake/fake_security_connector.h +9 -6
  135. data/src/core/lib/security/security_connector/local/local_security_connector.cc +176 -169
  136. data/src/core/lib/security/security_connector/local/local_security_connector.h +10 -9
  137. data/src/core/lib/security/security_connector/security_connector.cc +41 -124
  138. data/src/core/lib/security/security_connector/security_connector.h +102 -105
  139. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +348 -370
  140. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.h +14 -12
  141. data/src/core/lib/security/security_connector/ssl_utils.cc +13 -9
  142. data/src/core/lib/security/security_connector/ssl_utils.h +3 -1
  143. data/src/core/lib/security/transport/client_auth_filter.cc +50 -50
  144. data/src/core/lib/security/transport/secure_endpoint.cc +7 -1
  145. data/src/core/lib/security/transport/security_handshaker.cc +82 -66
  146. data/src/core/lib/security/transport/server_auth_filter.cc +15 -13
  147. data/src/core/lib/surface/init.cc +1 -0
  148. data/src/core/lib/surface/server.cc +13 -11
  149. data/src/core/lib/surface/server.h +6 -6
  150. data/src/core/lib/surface/version.cc +2 -2
  151. data/src/core/lib/transport/metadata.cc +1 -0
  152. data/src/core/lib/transport/static_metadata.cc +228 -221
  153. data/src/core/lib/transport/static_metadata.h +75 -71
  154. data/src/core/lib/transport/transport.cc +2 -1
  155. data/src/core/lib/transport/transport.h +5 -1
  156. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +9 -2
  157. data/src/core/tsi/ssl_transport_security.cc +35 -24
  158. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +1 -1
  159. data/src/ruby/lib/grpc/generic/rpc_server.rb +61 -0
  160. data/src/ruby/lib/grpc/generic/service.rb +1 -1
  161. data/src/ruby/lib/grpc/version.rb +1 -1
  162. data/src/ruby/pb/grpc/health/checker.rb +2 -3
  163. data/src/ruby/spec/generic/rpc_server_spec.rb +22 -0
  164. data/src/ruby/spec/support/services.rb +1 -0
  165. metadata +37 -32
  166. data/src/core/ext/filters/client_channel/lb_policy_factory.cc +0 -163
@@ -42,6 +42,7 @@ typedef struct grpc_fd grpc_fd;
42
42
  typedef struct grpc_event_engine_vtable {
43
43
  size_t pollset_size;
44
44
  bool can_track_err;
45
+ bool run_in_background;
45
46
 
46
47
  grpc_fd* (*fd_create)(int fd, const char* name, bool track_err);
47
48
  int (*fd_wrapped_fd)(grpc_fd* fd);
@@ -79,6 +80,7 @@ typedef struct grpc_event_engine_vtable {
79
80
  void (*pollset_set_add_fd)(grpc_pollset_set* pollset_set, grpc_fd* fd);
80
81
  void (*pollset_set_del_fd)(grpc_pollset_set* pollset_set, grpc_fd* fd);
81
82
 
83
+ void (*shutdown_background_closure)(void);
82
84
  void (*shutdown_engine)(void);
83
85
  } grpc_event_engine_vtable;
84
86
 
@@ -101,6 +103,11 @@ const char* grpc_get_poll_strategy_name();
101
103
  */
102
104
  bool grpc_event_engine_can_track_errors();
103
105
 
106
+ /* Returns true if polling engine runs in the background, false otherwise.
107
+ * Currently only 'epollbg' runs in the background.
108
+ */
109
+ bool grpc_event_engine_run_in_background();
110
+
104
111
  /* Create a wrapped file descriptor.
105
112
  Requires fd is a non-blocking file descriptor.
106
113
  \a track_err if true means that error events would be tracked separately
@@ -174,6 +181,9 @@ void grpc_pollset_add_fd(grpc_pollset* pollset, struct grpc_fd* fd);
174
181
  void grpc_pollset_set_add_fd(grpc_pollset_set* pollset_set, grpc_fd* fd);
175
182
  void grpc_pollset_set_del_fd(grpc_pollset_set* pollset_set, grpc_fd* fd);
176
183
 
184
+ /* Shut down all the closures registered in the background poller. */
185
+ void grpc_shutdown_background_closure();
186
+
177
187
  /* override to allow tests to hook poll() usage */
178
188
  typedef int (*grpc_poll_function_type)(struct pollfd*, nfds_t, int);
179
189
  extern grpc_poll_function_type grpc_poll_function;
@@ -53,6 +53,13 @@ static void exec_ctx_sched(grpc_closure* closure, grpc_error* error) {
53
53
 
54
54
  static gpr_timespec g_start_time;
55
55
 
56
+ // For debug of the timer manager crash only.
57
+ // TODO (mxyan): remove after bug is fixed.
58
+ #ifdef GRPC_DEBUG_TIMER_MANAGER
59
+ extern int64_t g_start_time_sec;
60
+ extern int64_t g_start_time_nsec;
61
+ #endif // GRPC_DEBUG_TIMER_MANAGER
62
+
56
63
  static grpc_millis timespec_to_millis_round_down(gpr_timespec ts) {
57
64
  ts = gpr_time_sub(ts, g_start_time);
58
65
  double x = GPR_MS_PER_SEC * static_cast<double>(ts.tv_sec) +
@@ -117,6 +124,12 @@ void ExecCtx::TestOnlyGlobalInit(gpr_timespec new_val) {
117
124
 
118
125
  void ExecCtx::GlobalInit(void) {
119
126
  g_start_time = gpr_now(GPR_CLOCK_MONOTONIC);
127
+ // For debug of the timer manager crash only.
128
+ // TODO (mxyan): remove after bug is fixed.
129
+ #ifdef GRPC_DEBUG_TIMER_MANAGER
130
+ g_start_time_sec = g_start_time.tv_sec;
131
+ g_start_time_nsec = g_start_time.tv_nsec;
132
+ #endif
120
133
  gpr_tls_init(&exec_ctx_);
121
134
  }
122
135
 
@@ -60,7 +60,7 @@ void grpc_prefork() {
60
60
  }
61
61
  if (strcmp(grpc_get_poll_strategy_name(), "epoll1") != 0 &&
62
62
  strcmp(grpc_get_poll_strategy_name(), "poll") != 0) {
63
- gpr_log(GPR_ERROR,
63
+ gpr_log(GPR_INFO,
64
64
  "Fork support is only compatible with the epoll1 and poll polling "
65
65
  "strategies");
66
66
  }
@@ -20,17 +20,50 @@
20
20
 
21
21
  #include "src/core/lib/iomgr/port.h"
22
22
 
23
+ #include <grpc/impl/codegen/log.h>
23
24
  #include "src/core/lib/iomgr/internal_errqueue.h"
24
25
 
25
26
  #ifdef GRPC_POSIX_SOCKET_TCP
26
27
 
27
- bool kernel_supports_errqueue() {
28
+ #include <errno.h>
29
+ #include <stdlib.h>
30
+ #include <string.h>
31
+ #include <sys/utsname.h>
32
+
33
+ namespace grpc_core {
34
+ static bool errqueue_supported = false;
35
+
36
+ bool kernel_supports_errqueue() { return errqueue_supported; }
37
+
38
+ void grpc_errqueue_init() {
39
+ /* Both-compile time and run-time linux kernel versions should be atleast 4.0.0
40
+ */
28
41
  #ifdef LINUX_VERSION_CODE
29
42
  #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0)
30
- return true;
43
+ struct utsname buffer;
44
+ if (uname(&buffer) != 0) {
45
+ gpr_log(GPR_ERROR, "uname: %s", strerror(errno));
46
+ return;
47
+ }
48
+ char* release = buffer.release;
49
+ if (release == nullptr) {
50
+ return;
51
+ }
52
+
53
+ if (strtol(release, nullptr, 10) >= 4) {
54
+ errqueue_supported = true;
55
+ } else {
56
+ gpr_log(GPR_DEBUG, "ERRQUEUE support not enabled");
57
+ }
31
58
  #endif /* LINUX_VERSION_CODE <= KERNEL_VERSION(4, 0, 0) */
32
59
  #endif /* LINUX_VERSION_CODE */
33
- return false;
34
60
  }
61
+ } /* namespace grpc_core */
62
+
63
+ #else
64
+
65
+ namespace grpc_core {
66
+ void grpc_errqueue_init() {}
67
+ } /* namespace grpc_core */
35
68
 
36
69
  #endif /* GRPC_POSIX_SOCKET_TCP */
@@ -76,8 +76,14 @@ constexpr uint32_t kTimestampingRecordingOptions =
76
76
  * Currently allowing only linux kernels above 4.0.0
77
77
  */
78
78
  bool kernel_supports_errqueue();
79
- } // namespace grpc_core
79
+
80
+ } /* namespace grpc_core */
80
81
 
81
82
  #endif /* GRPC_POSIX_SOCKET_TCP */
82
83
 
84
+ namespace grpc_core {
85
+ /* Initializes errqueue support */
86
+ void grpc_errqueue_init();
87
+ } /* namespace grpc_core */
88
+
83
89
  #endif /* GRPC_CORE_LIB_IOMGR_INTERNAL_ERRQUEUE_H */
@@ -33,8 +33,10 @@
33
33
  #include "src/core/lib/gpr/string.h"
34
34
  #include "src/core/lib/gpr/useful.h"
35
35
  #include "src/core/lib/gprpp/thd.h"
36
+ #include "src/core/lib/iomgr/buffer_list.h"
36
37
  #include "src/core/lib/iomgr/exec_ctx.h"
37
38
  #include "src/core/lib/iomgr/executor.h"
39
+ #include "src/core/lib/iomgr/internal_errqueue.h"
38
40
  #include "src/core/lib/iomgr/iomgr_internal.h"
39
41
  #include "src/core/lib/iomgr/network_status_tracker.h"
40
42
  #include "src/core/lib/iomgr/timer.h"
@@ -57,6 +59,7 @@ void grpc_iomgr_init() {
57
59
  g_root_object.name = (char*)"root";
58
60
  grpc_network_status_init();
59
61
  grpc_iomgr_platform_init();
62
+ grpc_core::grpc_errqueue_init();
60
63
  }
61
64
 
62
65
  void grpc_iomgr_start() { grpc_timer_manager_init(); }
@@ -154,6 +157,10 @@ void grpc_iomgr_shutdown() {
154
157
  gpr_cv_destroy(&g_rcv);
155
158
  }
156
159
 
160
+ void grpc_iomgr_shutdown_background_closure() {
161
+ grpc_iomgr_platform_shutdown_background_closure();
162
+ }
163
+
157
164
  void grpc_iomgr_register_object(grpc_iomgr_object* obj, const char* name) {
158
165
  obj->name = gpr_strdup(name);
159
166
  gpr_mu_lock(&g_mu);
@@ -35,6 +35,10 @@ void grpc_iomgr_start();
35
35
  * exec_ctx. */
36
36
  void grpc_iomgr_shutdown();
37
37
 
38
+ /** Signals the intention to shutdown all the closures registered in the
39
+ * background poller. */
40
+ void grpc_iomgr_shutdown_background_closure();
41
+
38
42
  /* Exposed only for testing */
39
43
  size_t grpc_iomgr_count_objects_for_testing();
40
44
 
@@ -40,9 +40,11 @@ static void iomgr_platform_init(void) {
40
40
  }
41
41
  static void iomgr_platform_flush(void) {}
42
42
  static void iomgr_platform_shutdown(void) { grpc_pollset_global_shutdown(); }
43
+ static void iomgr_platform_shutdown_background_closure(void) {}
43
44
 
44
45
  static grpc_iomgr_platform_vtable vtable = {
45
- iomgr_platform_init, iomgr_platform_flush, iomgr_platform_shutdown};
46
+ iomgr_platform_init, iomgr_platform_flush, iomgr_platform_shutdown,
47
+ iomgr_platform_shutdown_background_closure};
46
48
 
47
49
  void grpc_custom_iomgr_init(grpc_socket_vtable* socket,
48
50
  grpc_custom_resolver_vtable* resolver,
@@ -41,3 +41,7 @@ void grpc_iomgr_platform_init() { iomgr_platform_vtable->init(); }
41
41
  void grpc_iomgr_platform_flush() { iomgr_platform_vtable->flush(); }
42
42
 
43
43
  void grpc_iomgr_platform_shutdown() { iomgr_platform_vtable->shutdown(); }
44
+
45
+ void grpc_iomgr_platform_shutdown_background_closure() {
46
+ iomgr_platform_vtable->shutdown_background_closure();
47
+ }
@@ -35,6 +35,7 @@ typedef struct grpc_iomgr_platform_vtable {
35
35
  void (*init)(void);
36
36
  void (*flush)(void);
37
37
  void (*shutdown)(void);
38
+ void (*shutdown_background_closure)(void);
38
39
  } grpc_iomgr_platform_vtable;
39
40
 
40
41
  void grpc_iomgr_register_object(grpc_iomgr_object* obj, const char* name);
@@ -52,6 +53,9 @@ void grpc_iomgr_platform_flush(void);
52
53
  /** tear down all platform specific global iomgr structures */
53
54
  void grpc_iomgr_platform_shutdown(void);
54
55
 
56
+ /** shut down all the closures registered in the background poller */
57
+ void grpc_iomgr_platform_shutdown_background_closure(void);
58
+
55
59
  bool grpc_iomgr_abort_on_leaks(void);
56
60
 
57
61
  #endif /* GRPC_CORE_LIB_IOMGR_IOMGR_INTERNAL_H */
@@ -51,8 +51,13 @@ static void iomgr_platform_shutdown(void) {
51
51
  grpc_wakeup_fd_global_destroy();
52
52
  }
53
53
 
54
+ static void iomgr_platform_shutdown_background_closure(void) {
55
+ grpc_shutdown_background_closure();
56
+ }
57
+
54
58
  static grpc_iomgr_platform_vtable vtable = {
55
- iomgr_platform_init, iomgr_platform_flush, iomgr_platform_shutdown};
59
+ iomgr_platform_init, iomgr_platform_flush, iomgr_platform_shutdown,
60
+ iomgr_platform_shutdown_background_closure};
56
61
 
57
62
  void grpc_set_default_iomgr_platform() {
58
63
  grpc_set_tcp_client_impl(&grpc_posix_tcp_client_vtable);
@@ -71,8 +71,11 @@ static void iomgr_platform_shutdown(void) {
71
71
  winsock_shutdown();
72
72
  }
73
73
 
74
+ static void iomgr_platform_shutdown_background_closure(void) {}
75
+
74
76
  static grpc_iomgr_platform_vtable vtable = {
75
- iomgr_platform_init, iomgr_platform_flush, iomgr_platform_shutdown};
77
+ iomgr_platform_init, iomgr_platform_flush, iomgr_platform_shutdown,
78
+ iomgr_platform_shutdown_background_closure};
76
79
 
77
80
  void grpc_set_default_iomgr_platform() {
78
81
  grpc_set_tcp_client_impl(&grpc_windows_tcp_client_vtable);
@@ -62,8 +62,7 @@
62
62
  #define GRPC_HAVE_UNIX_SOCKET 1
63
63
  #ifdef LINUX_VERSION_CODE
64
64
  #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0)
65
- /* TODO(yashykt): Re-enable once Fathom changes are commited.
66
- #define GRPC_LINUX_ERRQUEUE 1 */
65
+ #define GRPC_LINUX_ERRQUEUE 1
67
66
  #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0) */
68
67
  #endif /* LINUX_VERSION_CODE */
69
68
  #define GRPC_LINUX_MULTIPOLL_WITH_EPOLL 1
@@ -665,6 +665,7 @@ void grpc_resource_quota_unref_internal(grpc_resource_quota* resource_quota) {
665
665
  GPR_ASSERT(resource_quota->num_threads_allocated == 0);
666
666
  GRPC_COMBINER_UNREF(resource_quota->combiner, "resource_quota");
667
667
  gpr_free(resource_quota->name);
668
+ gpr_mu_destroy(&resource_quota->thread_count_mu);
668
669
  gpr_free(resource_quota);
669
670
  }
670
671
  }
@@ -217,6 +217,7 @@ void grpc_string_to_sockaddr(grpc_resolved_address* out, char* addr, int port) {
217
217
  }
218
218
 
219
219
  char* grpc_sockaddr_to_uri(const grpc_resolved_address* resolved_addr) {
220
+ if (resolved_addr->len == 0) return nullptr;
220
221
  grpc_resolved_address addr_normalized;
221
222
  if (grpc_sockaddr_is_v4mapped(resolved_addr, &addr_normalized)) {
222
223
  resolved_addr = &addr_normalized;
@@ -326,6 +326,8 @@ static grpc_resource_user* endpoint_get_resource_user(grpc_endpoint* ep) {
326
326
 
327
327
  static int endpoint_get_fd(grpc_endpoint* ep) { return -1; }
328
328
 
329
+ static bool endpoint_can_track_err(grpc_endpoint* ep) { return false; }
330
+
329
331
  static grpc_endpoint_vtable vtable = {endpoint_read,
330
332
  endpoint_write,
331
333
  endpoint_add_to_pollset,
@@ -335,7 +337,8 @@ static grpc_endpoint_vtable vtable = {endpoint_read,
335
337
  endpoint_destroy,
336
338
  endpoint_get_resource_user,
337
339
  endpoint_get_peer,
338
- endpoint_get_fd};
340
+ endpoint_get_fd,
341
+ endpoint_can_track_err};
339
342
 
340
343
  grpc_endpoint* custom_tcp_endpoint_create(grpc_custom_socket* socket,
341
344
  grpc_resource_quota* resource_quota,
@@ -126,6 +126,7 @@ struct grpc_tcp {
126
126
  int bytes_counter;
127
127
  bool socket_ts_enabled; /* True if timestamping options are set on the socket
128
128
  */
129
+ bool ts_capable; /* Cache whether we can set timestamping options */
129
130
  gpr_atm
130
131
  stop_error_notification; /* Set to 1 if we do not want to be notified on
131
132
  errors anymore */
@@ -260,10 +261,17 @@ static void notify_on_write(grpc_tcp* tcp) {
260
261
  if (grpc_tcp_trace.enabled()) {
261
262
  gpr_log(GPR_INFO, "TCP:%p notify_on_write", tcp);
262
263
  }
263
- cover_self(tcp);
264
- GRPC_CLOSURE_INIT(&tcp->write_done_closure,
265
- tcp_drop_uncovered_then_handle_write, tcp,
266
- grpc_schedule_on_exec_ctx);
264
+ if (grpc_event_engine_run_in_background()) {
265
+ // If there is a polling engine always running in the background, there is
266
+ // no need to run the backup poller.
267
+ GRPC_CLOSURE_INIT(&tcp->write_done_closure, tcp_handle_write, tcp,
268
+ grpc_schedule_on_exec_ctx);
269
+ } else {
270
+ cover_self(tcp);
271
+ GRPC_CLOSURE_INIT(&tcp->write_done_closure,
272
+ tcp_drop_uncovered_then_handle_write, tcp,
273
+ grpc_schedule_on_exec_ctx);
274
+ }
267
275
  grpc_fd_notify_on_write(tcp->em_fd, &tcp->write_done_closure);
268
276
  }
269
277
 
@@ -384,6 +392,12 @@ static void tcp_destroy(grpc_endpoint* ep) {
384
392
  grpc_tcp* tcp = reinterpret_cast<grpc_tcp*>(ep);
385
393
  grpc_slice_buffer_reset_and_unref_internal(&tcp->last_read_buffer);
386
394
  if (grpc_event_engine_can_track_errors()) {
395
+ gpr_mu_lock(&tcp->tb_mu);
396
+ grpc_core::TracedBuffer::Shutdown(
397
+ &tcp->tb_head, tcp->outgoing_buffer_arg,
398
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("endpoint destroyed"));
399
+ gpr_mu_unlock(&tcp->tb_mu);
400
+ tcp->outgoing_buffer_arg = nullptr;
387
401
  gpr_atm_no_barrier_store(&tcp->stop_error_notification, true);
388
402
  grpc_fd_set_error(tcp->em_fd);
389
403
  }
@@ -576,7 +590,7 @@ ssize_t tcp_send(int fd, const struct msghdr* msg) {
576
590
  */
577
591
  static bool tcp_write_with_timestamps(grpc_tcp* tcp, struct msghdr* msg,
578
592
  size_t sending_length,
579
- ssize_t* sent_length, grpc_error** error);
593
+ ssize_t* sent_length);
580
594
 
581
595
  /** The callback function to be invoked when we get an error on the socket. */
582
596
  static void tcp_handle_error(void* arg /* grpc_tcp */, grpc_error* error);
@@ -584,13 +598,11 @@ static void tcp_handle_error(void* arg /* grpc_tcp */, grpc_error* error);
584
598
  #ifdef GRPC_LINUX_ERRQUEUE
585
599
  static bool tcp_write_with_timestamps(grpc_tcp* tcp, struct msghdr* msg,
586
600
  size_t sending_length,
587
- ssize_t* sent_length,
588
- grpc_error** error) {
601
+ ssize_t* sent_length) {
589
602
  if (!tcp->socket_ts_enabled) {
590
603
  uint32_t opt = grpc_core::kTimestampingSocketOptions;
591
604
  if (setsockopt(tcp->fd, SOL_SOCKET, SO_TIMESTAMPING,
592
605
  static_cast<void*>(&opt), sizeof(opt)) != 0) {
593
- *error = tcp_annotate_error(GRPC_OS_ERROR(errno, "setsockopt"), tcp);
594
606
  grpc_slice_buffer_reset_and_unref_internal(tcp->outgoing_buffer);
595
607
  if (grpc_tcp_trace.enabled()) {
596
608
  gpr_log(GPR_ERROR, "Failed to set timestamping options on the socket.");
@@ -621,7 +633,7 @@ static bool tcp_write_with_timestamps(grpc_tcp* tcp, struct msghdr* msg,
621
633
  if (sending_length == static_cast<size_t>(length)) {
622
634
  gpr_mu_lock(&tcp->tb_mu);
623
635
  grpc_core::TracedBuffer::AddNewEntry(
624
- &tcp->tb_head, static_cast<int>(tcp->bytes_counter + length),
636
+ &tcp->tb_head, static_cast<uint32_t>(tcp->bytes_counter + length),
625
637
  tcp->outgoing_buffer_arg);
626
638
  gpr_mu_unlock(&tcp->tb_mu);
627
639
  tcp->outgoing_buffer_arg = nullptr;
@@ -673,11 +685,9 @@ struct cmsghdr* process_timestamp(grpc_tcp* tcp, msghdr* msg,
673
685
  }
674
686
 
675
687
  /** For linux platforms, reads the socket's error queue and processes error
676
- * messages from the queue. Returns true if all the errors processed were
677
- * timestamps. Returns false if any of the errors were not timestamps. For
678
- * non-linux platforms, error processing is not used/enabled currently.
688
+ * messages from the queue.
679
689
  */
680
- static bool process_errors(grpc_tcp* tcp) {
690
+ static void process_errors(grpc_tcp* tcp) {
681
691
  while (true) {
682
692
  struct iovec iov;
683
693
  iov.iov_base = nullptr;
@@ -706,10 +716,10 @@ static bool process_errors(grpc_tcp* tcp) {
706
716
  } while (r < 0 && saved_errno == EINTR);
707
717
 
708
718
  if (r == -1 && saved_errno == EAGAIN) {
709
- return true; /* No more errors to process */
719
+ return; /* No more errors to process */
710
720
  }
711
721
  if (r == -1) {
712
- return false;
722
+ return;
713
723
  }
714
724
  if (grpc_tcp_trace.enabled()) {
715
725
  if ((msg.msg_flags & MSG_CTRUNC) == 1) {
@@ -719,8 +729,9 @@ static bool process_errors(grpc_tcp* tcp) {
719
729
 
720
730
  if (msg.msg_controllen == 0) {
721
731
  /* There was no control message found. It was probably spurious. */
722
- return true;
732
+ return;
723
733
  }
734
+ bool seen = false;
724
735
  for (auto cmsg = CMSG_FIRSTHDR(&msg); cmsg && cmsg->cmsg_len;
725
736
  cmsg = CMSG_NXTHDR(&msg, cmsg)) {
726
737
  if (cmsg->cmsg_level != SOL_SOCKET ||
@@ -732,9 +743,13 @@ static bool process_errors(grpc_tcp* tcp) {
732
743
  "unknown control message cmsg_level:%d cmsg_type:%d",
733
744
  cmsg->cmsg_level, cmsg->cmsg_type);
734
745
  }
735
- return false;
746
+ return;
736
747
  }
737
- process_timestamp(tcp, &msg, cmsg);
748
+ cmsg = process_timestamp(tcp, &msg, cmsg);
749
+ seen = true;
750
+ }
751
+ if (!seen) {
752
+ return;
738
753
  }
739
754
  }
740
755
  }
@@ -749,20 +764,17 @@ static void tcp_handle_error(void* arg /* grpc_tcp */, grpc_error* error) {
749
764
  static_cast<bool>(gpr_atm_acq_load(&tcp->stop_error_notification))) {
750
765
  /* We aren't going to register to hear on error anymore, so it is safe to
751
766
  * unref. */
752
- grpc_core::TracedBuffer::Shutdown(&tcp->tb_head, GRPC_ERROR_REF(error));
753
767
  TCP_UNREF(tcp, "error-tracking");
754
768
  return;
755
769
  }
756
770
 
757
771
  /* We are still interested in collecting timestamps, so let's try reading
758
772
  * them. */
759
- if (!process_errors(tcp)) {
760
- /* This was not a timestamps error. This was an actual error. Set the
761
- * read and write closures to be ready.
762
- */
763
- grpc_fd_set_readable(tcp->em_fd);
764
- grpc_fd_set_writable(tcp->em_fd);
765
- }
773
+ process_errors(tcp);
774
+ /* This might not a timestamps error. Set the read and write closures to be
775
+ * ready. */
776
+ grpc_fd_set_readable(tcp->em_fd);
777
+ grpc_fd_set_writable(tcp->em_fd);
766
778
  GRPC_CLOSURE_INIT(&tcp->error_closure, tcp_handle_error, tcp,
767
779
  grpc_schedule_on_exec_ctx);
768
780
  grpc_fd_notify_on_error(tcp->em_fd, &tcp->error_closure);
@@ -771,8 +783,7 @@ static void tcp_handle_error(void* arg /* grpc_tcp */, grpc_error* error) {
771
783
  #else /* GRPC_LINUX_ERRQUEUE */
772
784
  static bool tcp_write_with_timestamps(grpc_tcp* tcp, struct msghdr* msg,
773
785
  size_t sending_length,
774
- ssize_t* sent_length,
775
- grpc_error** error) {
786
+ ssize_t* sent_length) {
776
787
  gpr_log(GPR_ERROR, "Write with timestamps not supported for this platform");
777
788
  GPR_ASSERT(0);
778
789
  return false;
@@ -784,6 +795,19 @@ static void tcp_handle_error(void* arg /* grpc_tcp */, grpc_error* error) {
784
795
  }
785
796
  #endif /* GRPC_LINUX_ERRQUEUE */
786
797
 
798
+ /* If outgoing_buffer_arg is filled, shuts down the list early, so that any
799
+ * release operations needed can be performed on the arg */
800
+ void tcp_shutdown_buffer_list(grpc_tcp* tcp) {
801
+ if (tcp->outgoing_buffer_arg) {
802
+ gpr_mu_lock(&tcp->tb_mu);
803
+ grpc_core::TracedBuffer::Shutdown(
804
+ &tcp->tb_head, tcp->outgoing_buffer_arg,
805
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("TracedBuffer list shutdown"));
806
+ gpr_mu_unlock(&tcp->tb_mu);
807
+ tcp->outgoing_buffer_arg = nullptr;
808
+ }
809
+ }
810
+
787
811
  /* returns true if done, false if pending; if returning true, *error is set */
788
812
  #if defined(IOV_MAX) && IOV_MAX < 1000
789
813
  #define MAX_WRITE_IOVEC IOV_MAX
@@ -794,7 +818,7 @@ static bool tcp_flush(grpc_tcp* tcp, grpc_error** error) {
794
818
  struct msghdr msg;
795
819
  struct iovec iov[MAX_WRITE_IOVEC];
796
820
  msg_iovlen_type iov_size;
797
- ssize_t sent_length;
821
+ ssize_t sent_length = 0;
798
822
  size_t sending_length;
799
823
  size_t trailing;
800
824
  size_t unwind_slice_idx;
@@ -829,11 +853,19 @@ static bool tcp_flush(grpc_tcp* tcp, grpc_error** error) {
829
853
  msg.msg_iov = iov;
830
854
  msg.msg_iovlen = iov_size;
831
855
  msg.msg_flags = 0;
856
+ bool tried_sending_message = false;
832
857
  if (tcp->outgoing_buffer_arg != nullptr) {
833
- if (!tcp_write_with_timestamps(tcp, &msg, sending_length, &sent_length,
834
- error))
835
- return true; /* something went wrong with timestamps */
836
- } else {
858
+ if (!tcp->ts_capable ||
859
+ !tcp_write_with_timestamps(tcp, &msg, sending_length, &sent_length)) {
860
+ /* We could not set socket options to collect Fathom timestamps.
861
+ * Fallback on writing without timestamps. */
862
+ tcp->ts_capable = false;
863
+ tcp_shutdown_buffer_list(tcp);
864
+ } else {
865
+ tried_sending_message = true;
866
+ }
867
+ }
868
+ if (!tried_sending_message) {
837
869
  msg.msg_control = nullptr;
838
870
  msg.msg_controllen = 0;
839
871
 
@@ -856,10 +888,12 @@ static bool tcp_flush(grpc_tcp* tcp, grpc_error** error) {
856
888
  } else if (errno == EPIPE) {
857
889
  *error = tcp_annotate_error(GRPC_OS_ERROR(errno, "sendmsg"), tcp);
858
890
  grpc_slice_buffer_reset_and_unref_internal(tcp->outgoing_buffer);
891
+ tcp_shutdown_buffer_list(tcp);
859
892
  return true;
860
893
  } else {
861
894
  *error = tcp_annotate_error(GRPC_OS_ERROR(errno, "sendmsg"), tcp);
862
895
  grpc_slice_buffer_reset_and_unref_internal(tcp->outgoing_buffer);
896
+ tcp_shutdown_buffer_list(tcp);
863
897
  return true;
864
898
  }
865
899
  }
@@ -936,17 +970,18 @@ static void tcp_write(grpc_endpoint* ep, grpc_slice_buffer* buf,
936
970
 
937
971
  GPR_ASSERT(tcp->write_cb == nullptr);
938
972
 
973
+ tcp->outgoing_buffer_arg = arg;
939
974
  if (buf->length == 0) {
940
975
  GRPC_CLOSURE_SCHED(
941
976
  cb, grpc_fd_is_shutdown(tcp->em_fd)
942
977
  ? tcp_annotate_error(
943
978
  GRPC_ERROR_CREATE_FROM_STATIC_STRING("EOF"), tcp)
944
979
  : GRPC_ERROR_NONE);
980
+ tcp_shutdown_buffer_list(tcp);
945
981
  return;
946
982
  }
947
983
  tcp->outgoing_buffer = buf;
948
984
  tcp->outgoing_byte_idx = 0;
949
- tcp->outgoing_buffer_arg = arg;
950
985
  if (arg) {
951
986
  GPR_ASSERT(grpc_event_engine_can_track_errors());
952
987
  }
@@ -999,6 +1034,22 @@ static grpc_resource_user* tcp_get_resource_user(grpc_endpoint* ep) {
999
1034
  return tcp->resource_user;
1000
1035
  }
1001
1036
 
1037
+ static bool tcp_can_track_err(grpc_endpoint* ep) {
1038
+ grpc_tcp* tcp = reinterpret_cast<grpc_tcp*>(ep);
1039
+ if (!grpc_event_engine_can_track_errors()) {
1040
+ return false;
1041
+ }
1042
+ struct sockaddr addr;
1043
+ socklen_t len = sizeof(addr);
1044
+ if (getsockname(tcp->fd, &addr, &len) < 0) {
1045
+ return false;
1046
+ }
1047
+ if (addr.sa_family == AF_INET || addr.sa_family == AF_INET6) {
1048
+ return true;
1049
+ }
1050
+ return false;
1051
+ }
1052
+
1002
1053
  static const grpc_endpoint_vtable vtable = {tcp_read,
1003
1054
  tcp_write,
1004
1055
  tcp_add_to_pollset,
@@ -1008,7 +1059,8 @@ static const grpc_endpoint_vtable vtable = {tcp_read,
1008
1059
  tcp_destroy,
1009
1060
  tcp_get_resource_user,
1010
1061
  tcp_get_peer,
1011
- tcp_get_fd};
1062
+ tcp_get_fd,
1063
+ tcp_can_track_err};
1012
1064
 
1013
1065
  #define MAX_CHUNK_SIZE 32 * 1024 * 1024
1014
1066
 
@@ -1069,6 +1121,8 @@ grpc_endpoint* grpc_tcp_create(grpc_fd* em_fd,
1069
1121
  tcp->is_first_read = true;
1070
1122
  tcp->bytes_counter = -1;
1071
1123
  tcp->socket_ts_enabled = false;
1124
+ tcp->ts_capable = true;
1125
+ tcp->outgoing_buffer_arg = nullptr;
1072
1126
  /* paired with unref in grpc_tcp_destroy */
1073
1127
  gpr_ref_init(&tcp->refcount, 1);
1074
1128
  gpr_atm_no_barrier_store(&tcp->shutdown_count, 0);
@@ -1113,6 +1167,12 @@ void grpc_tcp_destroy_and_release_fd(grpc_endpoint* ep, int* fd,
1113
1167
  grpc_slice_buffer_reset_and_unref_internal(&tcp->last_read_buffer);
1114
1168
  if (grpc_event_engine_can_track_errors()) {
1115
1169
  /* Stop errors notification. */
1170
+ gpr_mu_lock(&tcp->tb_mu);
1171
+ grpc_core::TracedBuffer::Shutdown(
1172
+ &tcp->tb_head, tcp->outgoing_buffer_arg,
1173
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("endpoint destroyed"));
1174
+ gpr_mu_unlock(&tcp->tb_mu);
1175
+ tcp->outgoing_buffer_arg = nullptr;
1116
1176
  gpr_atm_no_barrier_store(&tcp->stop_error_notification, true);
1117
1177
  grpc_fd_set_error(tcp->em_fd);
1118
1178
  }