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.
- checksums.yaml +4 -4
- data/Makefile +1228 -988
- data/etc/roots.pem +242 -30
- data/include/grpc/grpc.h +2 -1
- data/include/grpc/grpc_security_constants.h +3 -3
- data/include/grpc/impl/codegen/atm_gcc_sync.h +2 -0
- data/include/grpc/impl/codegen/atm_windows.h +2 -0
- data/include/grpc/impl/codegen/compression_types.h +2 -1
- data/include/grpc/impl/codegen/grpc_types.h +1 -1
- data/include/grpc/impl/codegen/port_platform.h +9 -0
- data/src/core/ext/filters/client_channel/client_channel.cc +163 -882
- data/src/core/ext/filters/client_channel/health/health_check_client.cc +2 -4
- data/src/core/ext/filters/client_channel/health/health_check_client.h +2 -3
- data/src/core/ext/filters/client_channel/lb_policy.cc +1 -1
- data/src/core/ext/filters/client_channel/lb_policy.h +8 -17
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +176 -216
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +20 -23
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +49 -52
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +13 -35
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +31 -30
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +69 -225
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc +20 -23
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy_factory.h +2 -84
- data/src/core/ext/filters/client_channel/request_routing.cc +936 -0
- data/src/core/ext/filters/client_channel/request_routing.h +177 -0
- data/src/core/ext/filters/client_channel/resolver.cc +1 -1
- data/src/core/ext/filters/client_channel/resolver.h +1 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +37 -26
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +30 -18
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +119 -100
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +8 -5
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +5 -4
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc +2 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +12 -14
- data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +5 -9
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +2 -1
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +1 -2
- data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +17 -17
- data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +45 -52
- data/src/core/ext/filters/client_channel/resolver_result_parsing.h +13 -17
- data/src/core/ext/filters/client_channel/server_address.cc +103 -0
- data/src/core/ext/filters/client_channel/server_address.h +108 -0
- data/src/core/ext/filters/client_channel/subchannel.cc +10 -8
- data/src/core/ext/filters/client_channel/subchannel.h +9 -6
- data/src/core/ext/filters/client_channel/subchannel_index.cc +20 -27
- data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +3 -2
- data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +8 -9
- data/src/core/ext/transport/chttp2/server/chttp2_server.cc +1 -1
- data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +1 -1
- data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +8 -11
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +24 -54
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +3 -1
- data/src/core/ext/transport/chttp2/transport/context_list.cc +67 -0
- data/src/core/ext/transport/chttp2/transport/context_list.h +53 -0
- data/src/core/ext/transport/chttp2/transport/internal.h +38 -11
- data/src/core/ext/transport/chttp2/transport/writing.cc +5 -0
- data/src/core/ext/transport/inproc/inproc_transport.cc +1 -1
- data/src/core/lib/channel/channelz.cc +19 -18
- data/src/core/lib/channel/channelz.h +7 -1
- data/src/core/lib/channel/channelz_registry.cc +3 -2
- data/src/core/lib/debug/trace.cc +3 -0
- data/src/core/lib/debug/trace.h +5 -3
- data/src/core/lib/gpr/sync_posix.cc +96 -4
- data/src/core/lib/gprpp/inlined_vector.h +25 -19
- data/src/core/lib/gprpp/memory.h +2 -11
- data/src/core/lib/gprpp/orphanable.h +18 -82
- data/src/core/lib/gprpp/ref_counted.h +75 -84
- data/src/core/lib/gprpp/ref_counted_ptr.h +22 -17
- data/src/core/lib/http/httpcli_security_connector.cc +101 -94
- data/src/core/lib/http/parser.h +5 -5
- data/src/core/lib/iomgr/buffer_list.cc +16 -5
- data/src/core/lib/iomgr/buffer_list.h +10 -3
- data/src/core/lib/iomgr/call_combiner.cc +50 -2
- data/src/core/lib/iomgr/call_combiner.h +29 -2
- data/src/core/lib/iomgr/dynamic_annotations.h +67 -0
- data/src/core/lib/iomgr/endpoint.cc +4 -0
- data/src/core/lib/iomgr/endpoint.h +3 -0
- data/src/core/lib/iomgr/endpoint_pair_posix.cc +2 -2
- data/src/core/lib/iomgr/ev_epoll1_linux.cc +4 -0
- data/src/core/lib/iomgr/ev_epollex_linux.cc +4 -0
- data/src/core/lib/iomgr/ev_poll_posix.cc +4 -0
- data/src/core/lib/iomgr/ev_posix.cc +15 -7
- data/src/core/lib/iomgr/ev_posix.h +10 -0
- data/src/core/lib/iomgr/exec_ctx.cc +13 -0
- data/src/core/lib/iomgr/fork_posix.cc +1 -1
- data/src/core/lib/iomgr/internal_errqueue.cc +36 -3
- data/src/core/lib/iomgr/internal_errqueue.h +7 -1
- data/src/core/lib/iomgr/iomgr.cc +7 -0
- data/src/core/lib/iomgr/iomgr.h +4 -0
- data/src/core/lib/iomgr/iomgr_custom.cc +3 -1
- data/src/core/lib/iomgr/iomgr_internal.cc +4 -0
- data/src/core/lib/iomgr/iomgr_internal.h +4 -0
- data/src/core/lib/iomgr/iomgr_posix.cc +6 -1
- data/src/core/lib/iomgr/iomgr_windows.cc +4 -1
- data/src/core/lib/iomgr/port.h +1 -2
- data/src/core/lib/iomgr/resource_quota.cc +1 -0
- data/src/core/lib/iomgr/sockaddr_utils.cc +1 -0
- data/src/core/lib/iomgr/tcp_custom.cc +4 -1
- data/src/core/lib/iomgr/tcp_posix.cc +95 -35
- data/src/core/lib/iomgr/tcp_windows.cc +4 -1
- data/src/core/lib/iomgr/timer_manager.cc +6 -0
- data/src/core/lib/security/context/security_context.cc +75 -108
- data/src/core/lib/security/context/security_context.h +59 -35
- data/src/core/lib/security/credentials/alts/alts_credentials.cc +36 -48
- data/src/core/lib/security/credentials/alts/alts_credentials.h +37 -10
- data/src/core/lib/security/credentials/composite/composite_credentials.cc +97 -157
- data/src/core/lib/security/credentials/composite/composite_credentials.h +60 -24
- data/src/core/lib/security/credentials/credentials.cc +18 -142
- data/src/core/lib/security/credentials/credentials.h +119 -95
- data/src/core/lib/security/credentials/fake/fake_credentials.cc +46 -71
- data/src/core/lib/security/credentials/fake/fake_credentials.h +23 -5
- data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +144 -51
- data/src/core/lib/security/credentials/google_default/google_default_credentials.h +28 -5
- data/src/core/lib/security/credentials/iam/iam_credentials.cc +27 -35
- data/src/core/lib/security/credentials/iam/iam_credentials.h +18 -4
- data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +60 -69
- data/src/core/lib/security/credentials/jwt/jwt_credentials.h +29 -10
- data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +2 -0
- data/src/core/lib/security/credentials/local/local_credentials.cc +19 -32
- data/src/core/lib/security/credentials/local/local_credentials.h +32 -11
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +130 -149
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +74 -29
- data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +59 -77
- data/src/core/lib/security/credentials/plugin/plugin_credentials.h +40 -17
- data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +66 -83
- data/src/core/lib/security/credentials/ssl/ssl_credentials.h +58 -15
- data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +152 -177
- data/src/core/lib/security/security_connector/alts/alts_security_connector.h +12 -10
- data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +210 -215
- data/src/core/lib/security/security_connector/fake/fake_security_connector.h +9 -6
- data/src/core/lib/security/security_connector/local/local_security_connector.cc +176 -169
- data/src/core/lib/security/security_connector/local/local_security_connector.h +10 -9
- data/src/core/lib/security/security_connector/security_connector.cc +41 -124
- data/src/core/lib/security/security_connector/security_connector.h +102 -105
- data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +348 -370
- data/src/core/lib/security/security_connector/ssl/ssl_security_connector.h +14 -12
- data/src/core/lib/security/security_connector/ssl_utils.cc +13 -9
- data/src/core/lib/security/security_connector/ssl_utils.h +3 -1
- data/src/core/lib/security/transport/client_auth_filter.cc +50 -50
- data/src/core/lib/security/transport/secure_endpoint.cc +7 -1
- data/src/core/lib/security/transport/security_handshaker.cc +82 -66
- data/src/core/lib/security/transport/server_auth_filter.cc +15 -13
- data/src/core/lib/surface/init.cc +1 -0
- data/src/core/lib/surface/server.cc +13 -11
- data/src/core/lib/surface/server.h +6 -6
- data/src/core/lib/surface/version.cc +2 -2
- data/src/core/lib/transport/metadata.cc +1 -0
- data/src/core/lib/transport/static_metadata.cc +228 -221
- data/src/core/lib/transport/static_metadata.h +75 -71
- data/src/core/lib/transport/transport.cc +2 -1
- data/src/core/lib/transport/transport.h +5 -1
- data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +9 -2
- data/src/core/tsi/ssl_transport_security.cc +35 -24
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +1 -1
- data/src/ruby/lib/grpc/generic/rpc_server.rb +61 -0
- data/src/ruby/lib/grpc/generic/service.rb +1 -1
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/grpc/health/checker.rb +2 -3
- data/src/ruby/spec/generic/rpc_server_spec.rb +22 -0
- data/src/ruby/spec/support/services.rb +1 -0
- metadata +37 -32
- data/src/core/ext/filters/client_channel/lb_policy_factory.cc +0 -163
data/src/core/lib/http/parser.h
CHANGED
@@ -70,13 +70,13 @@ typedef struct grpc_http_request {
|
|
70
70
|
/* A response */
|
71
71
|
typedef struct grpc_http_response {
|
72
72
|
/* HTTP status code */
|
73
|
-
int status;
|
73
|
+
int status = 0;
|
74
74
|
/* Headers: count and key/values */
|
75
|
-
size_t hdr_count;
|
76
|
-
grpc_http_header* hdrs;
|
75
|
+
size_t hdr_count = 0;
|
76
|
+
grpc_http_header* hdrs = nullptr;
|
77
77
|
/* Body: length and contents; contents are NOT null-terminated */
|
78
|
-
size_t body_length;
|
79
|
-
char* body;
|
78
|
+
size_t body_length = 0;
|
79
|
+
char* body = nullptr;
|
80
80
|
} grpc_http_response;
|
81
81
|
|
82
82
|
typedef struct {
|
@@ -35,6 +35,9 @@ void TracedBuffer::AddNewEntry(TracedBuffer** head, uint32_t seq_no,
|
|
35
35
|
TracedBuffer* new_elem = New<TracedBuffer>(seq_no, arg);
|
36
36
|
/* Store the current time as the sendmsg time. */
|
37
37
|
new_elem->ts_.sendmsg_time = gpr_now(GPR_CLOCK_REALTIME);
|
38
|
+
new_elem->ts_.scheduled_time = gpr_inf_past(GPR_CLOCK_REALTIME);
|
39
|
+
new_elem->ts_.sent_time = gpr_inf_past(GPR_CLOCK_REALTIME);
|
40
|
+
new_elem->ts_.acked_time = gpr_inf_past(GPR_CLOCK_REALTIME);
|
38
41
|
if (*head == nullptr) {
|
39
42
|
*head = new_elem;
|
40
43
|
return;
|
@@ -55,10 +58,16 @@ void fill_gpr_from_timestamp(gpr_timespec* gts, const struct timespec* ts) {
|
|
55
58
|
gts->clock_type = GPR_CLOCK_REALTIME;
|
56
59
|
}
|
57
60
|
|
61
|
+
void default_timestamps_callback(void* arg, grpc_core::Timestamps* ts,
|
62
|
+
grpc_error* shudown_err) {
|
63
|
+
gpr_log(GPR_DEBUG, "Timestamps callback has not been registered");
|
64
|
+
}
|
65
|
+
|
58
66
|
/** The saved callback function that will be invoked when we get all the
|
59
67
|
* timestamps that we are going to get for a TracedBuffer. */
|
60
68
|
void (*timestamps_callback)(void*, grpc_core::Timestamps*,
|
61
|
-
grpc_error* shutdown_err)
|
69
|
+
grpc_error* shutdown_err) =
|
70
|
+
default_timestamps_callback;
|
62
71
|
} /* namespace */
|
63
72
|
|
64
73
|
void TracedBuffer::ProcessTimestamp(TracedBuffer** head,
|
@@ -99,18 +108,20 @@ void TracedBuffer::ProcessTimestamp(TracedBuffer** head,
|
|
99
108
|
}
|
100
109
|
}
|
101
110
|
|
102
|
-
void TracedBuffer::Shutdown(TracedBuffer** head,
|
111
|
+
void TracedBuffer::Shutdown(TracedBuffer** head, void* remaining,
|
112
|
+
grpc_error* shutdown_err) {
|
103
113
|
GPR_DEBUG_ASSERT(head != nullptr);
|
104
114
|
TracedBuffer* elem = *head;
|
105
115
|
while (elem != nullptr) {
|
106
|
-
|
107
|
-
timestamps_callback(elem->arg_, &(elem->ts_), shutdown_err);
|
108
|
-
}
|
116
|
+
timestamps_callback(elem->arg_, &(elem->ts_), shutdown_err);
|
109
117
|
auto* next = elem->next_;
|
110
118
|
Delete<TracedBuffer>(elem);
|
111
119
|
elem = next;
|
112
120
|
}
|
113
121
|
*head = nullptr;
|
122
|
+
if (remaining != nullptr) {
|
123
|
+
timestamps_callback(remaining, nullptr, shutdown_err);
|
124
|
+
}
|
114
125
|
GRPC_ERROR_UNREF(shutdown_err);
|
115
126
|
}
|
116
127
|
|
@@ -37,6 +37,8 @@ struct Timestamps {
|
|
37
37
|
gpr_timespec scheduled_time;
|
38
38
|
gpr_timespec sent_time;
|
39
39
|
gpr_timespec acked_time;
|
40
|
+
|
41
|
+
uint32_t byte_offset; /* byte offset relative to the start of the RPC */
|
40
42
|
};
|
41
43
|
|
42
44
|
/** TracedBuffer is a class to keep track of timestamps for a specific buffer in
|
@@ -67,13 +69,13 @@ class TracedBuffer {
|
|
67
69
|
|
68
70
|
/** Cleans the list by calling the callback for each traced buffer in the list
|
69
71
|
* with timestamps that it has. */
|
70
|
-
static void Shutdown(grpc_core::TracedBuffer** head,
|
72
|
+
static void Shutdown(grpc_core::TracedBuffer** head, void* remaining,
|
71
73
|
grpc_error* shutdown_err);
|
72
74
|
|
73
75
|
private:
|
74
76
|
GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_NEW
|
75
77
|
|
76
|
-
TracedBuffer(
|
78
|
+
TracedBuffer(uint32_t seq_no, void* arg)
|
77
79
|
: seq_no_(seq_no), arg_(arg), next_(nullptr) {}
|
78
80
|
|
79
81
|
uint32_t seq_no_; /* The sequence number for the last byte in the buffer */
|
@@ -82,7 +84,12 @@ class TracedBuffer {
|
|
82
84
|
grpc_core::TracedBuffer* next_; /* The next TracedBuffer in the list */
|
83
85
|
};
|
84
86
|
#else /* GRPC_LINUX_ERRQUEUE */
|
85
|
-
class TracedBuffer {
|
87
|
+
class TracedBuffer {
|
88
|
+
public:
|
89
|
+
/* Dummy shutdown function */
|
90
|
+
static void Shutdown(grpc_core::TracedBuffer** head, void* remaining,
|
91
|
+
grpc_error* shutdown_err) {}
|
92
|
+
};
|
86
93
|
#endif /* GRPC_LINUX_ERRQUEUE */
|
87
94
|
|
88
95
|
/** Sets the callback function to call when timestamps for a write are
|
@@ -39,10 +39,57 @@ static gpr_atm encode_cancel_state_error(grpc_error* error) {
|
|
39
39
|
return static_cast<gpr_atm>(1) | (gpr_atm)error;
|
40
40
|
}
|
41
41
|
|
42
|
+
#ifdef GRPC_TSAN_ENABLED
|
43
|
+
static void tsan_closure(void* user_data, grpc_error* error) {
|
44
|
+
grpc_call_combiner* call_combiner =
|
45
|
+
static_cast<grpc_call_combiner*>(user_data);
|
46
|
+
// We ref-count the lock, and check if it's already taken.
|
47
|
+
// If it was taken, we should do nothing. Otherwise, we will mark it as
|
48
|
+
// locked. Note that if two different threads try to do this, only one of
|
49
|
+
// them will be able to mark the lock as acquired, while they both run their
|
50
|
+
// callbacks. In such cases (which should never happen for call_combiner),
|
51
|
+
// TSAN will correctly produce an error.
|
52
|
+
//
|
53
|
+
// TODO(soheil): This only covers the callbacks scheduled by
|
54
|
+
// grpc_call_combiner_(start|finish). If in the future, a
|
55
|
+
// callback gets scheduled using other mechanisms, we will need
|
56
|
+
// to add APIs to externally lock call combiners.
|
57
|
+
grpc_core::RefCountedPtr<grpc_call_combiner::TsanLock> lock =
|
58
|
+
call_combiner->tsan_lock;
|
59
|
+
bool prev = false;
|
60
|
+
if (lock->taken.compare_exchange_strong(prev, true)) {
|
61
|
+
TSAN_ANNOTATE_RWLOCK_ACQUIRED(&lock->taken, true);
|
62
|
+
} else {
|
63
|
+
lock.reset();
|
64
|
+
}
|
65
|
+
GRPC_CLOSURE_RUN(call_combiner->original_closure, GRPC_ERROR_REF(error));
|
66
|
+
if (lock != nullptr) {
|
67
|
+
TSAN_ANNOTATE_RWLOCK_RELEASED(&lock->taken, true);
|
68
|
+
bool prev = true;
|
69
|
+
GPR_ASSERT(lock->taken.compare_exchange_strong(prev, false));
|
70
|
+
}
|
71
|
+
}
|
72
|
+
#endif
|
73
|
+
|
74
|
+
static void call_combiner_sched_closure(grpc_call_combiner* call_combiner,
|
75
|
+
grpc_closure* closure,
|
76
|
+
grpc_error* error) {
|
77
|
+
#ifdef GRPC_TSAN_ENABLED
|
78
|
+
call_combiner->original_closure = closure;
|
79
|
+
GRPC_CLOSURE_SCHED(&call_combiner->tsan_closure, error);
|
80
|
+
#else
|
81
|
+
GRPC_CLOSURE_SCHED(closure, error);
|
82
|
+
#endif
|
83
|
+
}
|
84
|
+
|
42
85
|
void grpc_call_combiner_init(grpc_call_combiner* call_combiner) {
|
43
86
|
gpr_atm_no_barrier_store(&call_combiner->cancel_state, 0);
|
44
87
|
gpr_atm_no_barrier_store(&call_combiner->size, 0);
|
45
88
|
gpr_mpscq_init(&call_combiner->queue);
|
89
|
+
#ifdef GRPC_TSAN_ENABLED
|
90
|
+
GRPC_CLOSURE_INIT(&call_combiner->tsan_closure, tsan_closure, call_combiner,
|
91
|
+
grpc_schedule_on_exec_ctx);
|
92
|
+
#endif
|
46
93
|
}
|
47
94
|
|
48
95
|
void grpc_call_combiner_destroy(grpc_call_combiner* call_combiner) {
|
@@ -87,7 +134,7 @@ void grpc_call_combiner_start(grpc_call_combiner* call_combiner,
|
|
87
134
|
gpr_log(GPR_INFO, " EXECUTING IMMEDIATELY");
|
88
135
|
}
|
89
136
|
// Queue was empty, so execute this closure immediately.
|
90
|
-
|
137
|
+
call_combiner_sched_closure(call_combiner, closure, error);
|
91
138
|
} else {
|
92
139
|
if (grpc_call_combiner_trace.enabled()) {
|
93
140
|
gpr_log(GPR_INFO, " QUEUING");
|
@@ -134,7 +181,8 @@ void grpc_call_combiner_stop(grpc_call_combiner* call_combiner DEBUG_ARGS,
|
|
134
181
|
gpr_log(GPR_INFO, " EXECUTING FROM QUEUE: closure=%p error=%s",
|
135
182
|
closure, grpc_error_string(closure->error_data.error));
|
136
183
|
}
|
137
|
-
|
184
|
+
call_combiner_sched_closure(call_combiner, closure,
|
185
|
+
closure->error_data.error);
|
138
186
|
break;
|
139
187
|
}
|
140
188
|
} else if (grpc_call_combiner_trace.enabled()) {
|
@@ -27,7 +27,10 @@
|
|
27
27
|
|
28
28
|
#include "src/core/lib/gpr/mpscq.h"
|
29
29
|
#include "src/core/lib/gprpp/inlined_vector.h"
|
30
|
+
#include "src/core/lib/gprpp/ref_counted.h"
|
31
|
+
#include "src/core/lib/gprpp/ref_counted_ptr.h"
|
30
32
|
#include "src/core/lib/iomgr/closure.h"
|
33
|
+
#include "src/core/lib/iomgr/dynamic_annotations.h"
|
31
34
|
|
32
35
|
// A simple, lock-free mechanism for serializing activity related to a
|
33
36
|
// single call. This is similar to a combiner but is more lightweight.
|
@@ -40,14 +43,38 @@
|
|
40
43
|
|
41
44
|
extern grpc_core::TraceFlag grpc_call_combiner_trace;
|
42
45
|
|
43
|
-
|
46
|
+
struct grpc_call_combiner {
|
44
47
|
gpr_atm size = 0; // size_t, num closures in queue or currently executing
|
45
48
|
gpr_mpscq queue;
|
46
49
|
// Either 0 (if not cancelled and no cancellation closure set),
|
47
50
|
// a grpc_closure* (if the lowest bit is 0),
|
48
51
|
// or a grpc_error* (if the lowest bit is 1).
|
49
52
|
gpr_atm cancel_state = 0;
|
50
|
-
|
53
|
+
#ifdef GRPC_TSAN_ENABLED
|
54
|
+
// A fake ref-counted lock that is kept alive after the destruction of
|
55
|
+
// grpc_call_combiner, when we are running the original closure.
|
56
|
+
//
|
57
|
+
// Ideally we want to lock and unlock the call combiner as a pointer, when the
|
58
|
+
// callback is called. However, original_closure is free to trigger
|
59
|
+
// anything on the call combiner (including destruction of grpc_call).
|
60
|
+
// Thus, we need a ref-counted structure that can outlive the call combiner.
|
61
|
+
struct TsanLock
|
62
|
+
: public grpc_core::RefCounted<TsanLock,
|
63
|
+
grpc_core::NonPolymorphicRefCount> {
|
64
|
+
TsanLock() { TSAN_ANNOTATE_RWLOCK_CREATE(&taken); }
|
65
|
+
~TsanLock() { TSAN_ANNOTATE_RWLOCK_DESTROY(&taken); }
|
66
|
+
|
67
|
+
// To avoid double-locking by the same thread, we should acquire/release
|
68
|
+
// the lock only when taken is false. On each acquire taken must be set to
|
69
|
+
// true.
|
70
|
+
std::atomic<bool> taken{false};
|
71
|
+
};
|
72
|
+
grpc_core::RefCountedPtr<TsanLock> tsan_lock =
|
73
|
+
grpc_core::MakeRefCounted<TsanLock>();
|
74
|
+
grpc_closure tsan_closure;
|
75
|
+
grpc_closure* original_closure;
|
76
|
+
#endif
|
77
|
+
};
|
51
78
|
|
52
79
|
// Assumes memory was initialized to zero.
|
53
80
|
void grpc_call_combiner_init(grpc_call_combiner* call_combiner);
|
@@ -0,0 +1,67 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2018 gRPC authors.
|
4
|
+
*
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
* you may not use this file except in compliance with the License.
|
7
|
+
* You may obtain a copy of the License at
|
8
|
+
*
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
*
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
* See the License for the specific language governing permissions and
|
15
|
+
* limitations under the License.
|
16
|
+
*
|
17
|
+
*/
|
18
|
+
|
19
|
+
#ifndef GRPC_CORE_LIB_IOMGR_DYNAMIC_ANNOTATIONS_H
|
20
|
+
#define GRPC_CORE_LIB_IOMGR_DYNAMIC_ANNOTATIONS_H
|
21
|
+
|
22
|
+
#include <grpc/support/port_platform.h>
|
23
|
+
|
24
|
+
#ifdef GRPC_TSAN_ENABLED
|
25
|
+
|
26
|
+
#define TSAN_ANNOTATE_HAPPENS_BEFORE(addr) \
|
27
|
+
AnnotateHappensBefore(__FILE__, __LINE__, (void*)(addr))
|
28
|
+
#define TSAN_ANNOTATE_HAPPENS_AFTER(addr) \
|
29
|
+
AnnotateHappensAfter(__FILE__, __LINE__, (void*)(addr))
|
30
|
+
#define TSAN_ANNOTATE_RWLOCK_CREATE(addr) \
|
31
|
+
AnnotateRWLockCreate(__FILE__, __LINE__, (void*)(addr))
|
32
|
+
#define TSAN_ANNOTATE_RWLOCK_DESTROY(addr) \
|
33
|
+
AnnotateRWLockDestroy(__FILE__, __LINE__, (void*)(addr))
|
34
|
+
#define TSAN_ANNOTATE_RWLOCK_ACQUIRED(addr, is_w) \
|
35
|
+
AnnotateRWLockAcquired(__FILE__, __LINE__, (void*)(addr), (is_w))
|
36
|
+
#define TSAN_ANNOTATE_RWLOCK_RELEASED(addr, is_w) \
|
37
|
+
AnnotateRWLockReleased(__FILE__, __LINE__, (void*)(addr), (is_w))
|
38
|
+
|
39
|
+
#ifdef __cplusplus
|
40
|
+
extern "C" {
|
41
|
+
#endif
|
42
|
+
void AnnotateHappensBefore(const char* file, int line, const volatile void* cv);
|
43
|
+
void AnnotateHappensAfter(const char* file, int line, const volatile void* cv);
|
44
|
+
void AnnotateRWLockCreate(const char* file, int line,
|
45
|
+
const volatile void* lock);
|
46
|
+
void AnnotateRWLockDestroy(const char* file, int line,
|
47
|
+
const volatile void* lock);
|
48
|
+
void AnnotateRWLockAcquired(const char* file, int line,
|
49
|
+
const volatile void* lock, long is_w);
|
50
|
+
void AnnotateRWLockReleased(const char* file, int line,
|
51
|
+
const volatile void* lock, long is_w);
|
52
|
+
#ifdef __cplusplus
|
53
|
+
}
|
54
|
+
#endif
|
55
|
+
|
56
|
+
#else /* GRPC_TSAN_ENABLED */
|
57
|
+
|
58
|
+
#define TSAN_ANNOTATE_HAPPENS_BEFORE(addr)
|
59
|
+
#define TSAN_ANNOTATE_HAPPENS_AFTER(addr)
|
60
|
+
#define TSAN_ANNOTATE_RWLOCK_CREATE(addr)
|
61
|
+
#define TSAN_ANNOTATE_RWLOCK_DESTROY(addr)
|
62
|
+
#define TSAN_ANNOTATE_RWLOCK_ACQUIRED(addr, is_w)
|
63
|
+
#define TSAN_ANNOTATE_RWLOCK_RELEASED(addr, is_w)
|
64
|
+
|
65
|
+
#endif /* GRPC_TSAN_ENABLED */
|
66
|
+
|
67
|
+
#endif /* GRPC_CORE_LIB_IOMGR_DYNAMIC_ANNOTATIONS_H */
|
@@ -61,3 +61,7 @@ int grpc_endpoint_get_fd(grpc_endpoint* ep) { return ep->vtable->get_fd(ep); }
|
|
61
61
|
grpc_resource_user* grpc_endpoint_get_resource_user(grpc_endpoint* ep) {
|
62
62
|
return ep->vtable->get_resource_user(ep);
|
63
63
|
}
|
64
|
+
|
65
|
+
bool grpc_endpoint_can_track_err(grpc_endpoint* ep) {
|
66
|
+
return ep->vtable->can_track_err(ep);
|
67
|
+
}
|
@@ -47,6 +47,7 @@ struct grpc_endpoint_vtable {
|
|
47
47
|
grpc_resource_user* (*get_resource_user)(grpc_endpoint* ep);
|
48
48
|
char* (*get_peer)(grpc_endpoint* ep);
|
49
49
|
int (*get_fd)(grpc_endpoint* ep);
|
50
|
+
bool (*can_track_err)(grpc_endpoint* ep);
|
50
51
|
};
|
51
52
|
|
52
53
|
/* When data is available on the connection, calls the callback with slices.
|
@@ -95,6 +96,8 @@ void grpc_endpoint_delete_from_pollset_set(grpc_endpoint* ep,
|
|
95
96
|
|
96
97
|
grpc_resource_user* grpc_endpoint_get_resource_user(grpc_endpoint* endpoint);
|
97
98
|
|
99
|
+
bool grpc_endpoint_can_track_err(grpc_endpoint* ep);
|
100
|
+
|
98
101
|
struct grpc_endpoint {
|
99
102
|
const grpc_endpoint_vtable* vtable;
|
100
103
|
};
|
@@ -59,11 +59,11 @@ grpc_endpoint_pair grpc_iomgr_create_endpoint_pair(const char* name,
|
|
59
59
|
grpc_core::ExecCtx exec_ctx;
|
60
60
|
|
61
61
|
gpr_asprintf(&final_name, "%s:client", name);
|
62
|
-
p.client = grpc_tcp_create(grpc_fd_create(sv[1], final_name,
|
62
|
+
p.client = grpc_tcp_create(grpc_fd_create(sv[1], final_name, false), args,
|
63
63
|
"socketpair-server");
|
64
64
|
gpr_free(final_name);
|
65
65
|
gpr_asprintf(&final_name, "%s:server", name);
|
66
|
-
p.server = grpc_tcp_create(grpc_fd_create(sv[0], final_name,
|
66
|
+
p.server = grpc_tcp_create(grpc_fd_create(sv[0], final_name, false), args,
|
67
67
|
"socketpair-client");
|
68
68
|
gpr_free(final_name);
|
69
69
|
|
@@ -1242,6 +1242,8 @@ static void pollset_set_del_pollset_set(grpc_pollset_set* bag,
|
|
1242
1242
|
* Event engine binding
|
1243
1243
|
*/
|
1244
1244
|
|
1245
|
+
static void shutdown_background_closure(void) {}
|
1246
|
+
|
1245
1247
|
static void shutdown_engine(void) {
|
1246
1248
|
fd_global_shutdown();
|
1247
1249
|
pollset_global_shutdown();
|
@@ -1255,6 +1257,7 @@ static void shutdown_engine(void) {
|
|
1255
1257
|
static const grpc_event_engine_vtable vtable = {
|
1256
1258
|
sizeof(grpc_pollset),
|
1257
1259
|
true,
|
1260
|
+
false,
|
1258
1261
|
|
1259
1262
|
fd_create,
|
1260
1263
|
fd_wrapped_fd,
|
@@ -1284,6 +1287,7 @@ static const grpc_event_engine_vtable vtable = {
|
|
1284
1287
|
pollset_set_add_fd,
|
1285
1288
|
pollset_set_del_fd,
|
1286
1289
|
|
1290
|
+
shutdown_background_closure,
|
1287
1291
|
shutdown_engine,
|
1288
1292
|
};
|
1289
1293
|
|
@@ -1604,6 +1604,8 @@ static void pollset_set_del_pollset_set(grpc_pollset_set* bag,
|
|
1604
1604
|
* Event engine binding
|
1605
1605
|
*/
|
1606
1606
|
|
1607
|
+
static void shutdown_background_closure(void) {}
|
1608
|
+
|
1607
1609
|
static void shutdown_engine(void) {
|
1608
1610
|
fd_global_shutdown();
|
1609
1611
|
pollset_global_shutdown();
|
@@ -1612,6 +1614,7 @@ static void shutdown_engine(void) {
|
|
1612
1614
|
static const grpc_event_engine_vtable vtable = {
|
1613
1615
|
sizeof(grpc_pollset),
|
1614
1616
|
true,
|
1617
|
+
false,
|
1615
1618
|
|
1616
1619
|
fd_create,
|
1617
1620
|
fd_wrapped_fd,
|
@@ -1641,6 +1644,7 @@ static const grpc_event_engine_vtable vtable = {
|
|
1641
1644
|
pollset_set_add_fd,
|
1642
1645
|
pollset_set_del_fd,
|
1643
1646
|
|
1647
|
+
shutdown_background_closure,
|
1644
1648
|
shutdown_engine,
|
1645
1649
|
};
|
1646
1650
|
|
@@ -1782,6 +1782,8 @@ static void global_cv_fd_table_shutdown() {
|
|
1782
1782
|
* event engine binding
|
1783
1783
|
*/
|
1784
1784
|
|
1785
|
+
static void shutdown_background_closure(void) {}
|
1786
|
+
|
1785
1787
|
static void shutdown_engine(void) {
|
1786
1788
|
pollset_global_shutdown();
|
1787
1789
|
if (grpc_cv_wakeup_fds_enabled()) {
|
@@ -1796,6 +1798,7 @@ static void shutdown_engine(void) {
|
|
1796
1798
|
static const grpc_event_engine_vtable vtable = {
|
1797
1799
|
sizeof(grpc_pollset),
|
1798
1800
|
false,
|
1801
|
+
false,
|
1799
1802
|
|
1800
1803
|
fd_create,
|
1801
1804
|
fd_wrapped_fd,
|
@@ -1825,6 +1828,7 @@ static const grpc_event_engine_vtable vtable = {
|
|
1825
1828
|
pollset_set_add_fd,
|
1826
1829
|
pollset_set_del_fd,
|
1827
1830
|
|
1831
|
+
shutdown_background_closure,
|
1828
1832
|
shutdown_engine,
|
1829
1833
|
};
|
1830
1834
|
|
@@ -36,6 +36,7 @@
|
|
36
36
|
#include "src/core/lib/iomgr/ev_epoll1_linux.h"
|
37
37
|
#include "src/core/lib/iomgr/ev_epollex_linux.h"
|
38
38
|
#include "src/core/lib/iomgr/ev_poll_posix.h"
|
39
|
+
#include "src/core/lib/iomgr/internal_errqueue.h"
|
39
40
|
|
40
41
|
grpc_core::TraceFlag grpc_polling_trace(false,
|
41
42
|
"polling"); /* Disabled by default */
|
@@ -236,19 +237,22 @@ void grpc_event_engine_shutdown(void) {
|
|
236
237
|
}
|
237
238
|
|
238
239
|
bool grpc_event_engine_can_track_errors(void) {
|
239
|
-
/* Only track errors if platform supports errqueue. */
|
240
|
-
|
241
|
-
|
242
|
-
|
240
|
+
/* Only track errors if platform supports errqueue. */
|
241
|
+
if (grpc_core::kernel_supports_errqueue()) {
|
242
|
+
return g_event_engine->can_track_err;
|
243
|
+
}
|
243
244
|
return false;
|
244
|
-
|
245
|
+
}
|
246
|
+
|
247
|
+
bool grpc_event_engine_run_in_background(void) {
|
248
|
+
return g_event_engine->run_in_background;
|
245
249
|
}
|
246
250
|
|
247
251
|
grpc_fd* grpc_fd_create(int fd, const char* name, bool track_err) {
|
248
252
|
GRPC_POLLING_API_TRACE("fd_create(%d, %s, %d)", fd, name, track_err);
|
249
253
|
GRPC_FD_TRACE("fd_create(%d, %s, %d)", fd, name, track_err);
|
250
|
-
return g_event_engine->fd_create(
|
251
|
-
|
254
|
+
return g_event_engine->fd_create(
|
255
|
+
fd, name, track_err && grpc_event_engine_can_track_errors());
|
252
256
|
}
|
253
257
|
|
254
258
|
int grpc_fd_wrapped_fd(grpc_fd* fd) {
|
@@ -395,4 +399,8 @@ void grpc_pollset_set_del_fd(grpc_pollset_set* pollset_set, grpc_fd* fd) {
|
|
395
399
|
g_event_engine->pollset_set_del_fd(pollset_set, fd);
|
396
400
|
}
|
397
401
|
|
402
|
+
void grpc_shutdown_background_closure(void) {
|
403
|
+
g_event_engine->shutdown_background_closure();
|
404
|
+
}
|
405
|
+
|
398
406
|
#endif // GRPC_POSIX_SOCKET_EV
|