grpc 1.2.2-x86-linux → 1.2.5-x86-linux
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/grpc_c.32.ruby +0 -0
- data/grpc_c.64.ruby +0 -0
- data/src/ruby/ext/grpc/rb_channel.c +72 -262
- data/src/ruby/lib/grpc/2.0/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/2.1/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/2.2/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/2.3/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/2.4/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/spec/channel_spec.rb +0 -29
- metadata +2 -4
- data/src/ruby/spec/channel_connection_spec.rb +0 -141
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8cb2b2c9017d97a631ebb8017bad50111335bdf
|
4
|
+
data.tar.gz: 0af978fcd0e28cc7847afb829ed15e50892074c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61df58ccff91be063258705f4f60ede194e1f892261e15652918fd13c9ec57119b52aa8f97f65881a3398bed2063fe7f938b397520f6591a7630198bd2522a9b
|
7
|
+
data.tar.gz: 8fb17d7ade2133d2200b5d2aaa72e53c6f44bb0d28408f44e566b408224091d3de8847991dfcff5f3c52c852826c95a1285f768c3772caed1cd017993dd0186b
|
data/grpc_c.32.ruby
CHANGED
Binary file
|
data/grpc_c.64.ruby
CHANGED
Binary file
|
@@ -32,24 +32,26 @@
|
|
32
32
|
*/
|
33
33
|
|
34
34
|
#include <ruby/ruby.h>
|
35
|
-
#include <ruby/thread.h>
|
36
35
|
|
37
36
|
#include "rb_grpc_imports.generated.h"
|
38
|
-
#include "rb_byte_buffer.h"
|
39
37
|
#include "rb_channel.h"
|
38
|
+
#include "rb_byte_buffer.h"
|
40
39
|
|
41
40
|
#include <grpc/grpc.h>
|
42
41
|
#include <grpc/grpc_security.h>
|
43
42
|
#include <grpc/support/alloc.h>
|
44
43
|
#include <grpc/support/log.h>
|
45
44
|
#include <grpc/support/time.h>
|
45
|
+
#include "rb_grpc.h"
|
46
46
|
#include "rb_call.h"
|
47
47
|
#include "rb_channel_args.h"
|
48
48
|
#include "rb_channel_credentials.h"
|
49
49
|
#include "rb_completion_queue.h"
|
50
|
-
#include "rb_grpc.h"
|
51
50
|
#include "rb_server.h"
|
52
51
|
|
52
|
+
// TODO: During v1.2.x upmerge to master, no changes from this file should go
|
53
|
+
// in to master. This is reverted for 1.2.x only.
|
54
|
+
|
53
55
|
/* id_channel is the name of the hidden ivar that preserves a reference to the
|
54
56
|
* channel on a call, so that calls are not GCed before their channel. */
|
55
57
|
static ID id_channel;
|
@@ -74,26 +76,9 @@ typedef struct grpc_rb_channel {
|
|
74
76
|
|
75
77
|
/* The actual channel */
|
76
78
|
grpc_channel *wrapped;
|
77
|
-
|
78
|
-
int safe_to_destroy;
|
79
|
-
grpc_connectivity_state current_connectivity_state;
|
80
|
-
|
81
|
-
int mu_init_done;
|
82
|
-
int abort_watch_connectivity_state;
|
83
|
-
gpr_mu channel_mu;
|
84
|
-
gpr_cv channel_cv;
|
79
|
+
grpc_completion_queue *queue;
|
85
80
|
} grpc_rb_channel;
|
86
81
|
|
87
|
-
/* Forward declarations of functions involved in temporary fix to
|
88
|
-
* https://github.com/grpc/grpc/issues/9941 */
|
89
|
-
static void grpc_rb_channel_try_register_connection_polling(
|
90
|
-
grpc_rb_channel *wrapper);
|
91
|
-
static void grpc_rb_channel_safe_destroy(grpc_rb_channel *wrapper);
|
92
|
-
|
93
|
-
static grpc_completion_queue *channel_polling_cq;
|
94
|
-
static gpr_mu global_connection_polling_mu;
|
95
|
-
static int abort_channel_polling = 0;
|
96
|
-
|
97
82
|
/* Destroys Channel instances. */
|
98
83
|
static void grpc_rb_channel_free(void *p) {
|
99
84
|
grpc_rb_channel *ch = NULL;
|
@@ -103,13 +88,8 @@ static void grpc_rb_channel_free(void *p) {
|
|
103
88
|
ch = (grpc_rb_channel *)p;
|
104
89
|
|
105
90
|
if (ch->wrapped != NULL) {
|
106
|
-
|
107
|
-
ch->
|
108
|
-
}
|
109
|
-
|
110
|
-
if (ch->mu_init_done) {
|
111
|
-
gpr_mu_destroy(&ch->channel_mu);
|
112
|
-
gpr_cv_destroy(&ch->channel_cv);
|
91
|
+
grpc_channel_destroy(ch->wrapped);
|
92
|
+
grpc_rb_completion_queue_destroy(ch->queue);
|
113
93
|
}
|
114
94
|
|
115
95
|
xfree(p);
|
@@ -127,15 +107,13 @@ static void grpc_rb_channel_mark(void *p) {
|
|
127
107
|
}
|
128
108
|
}
|
129
109
|
|
130
|
-
static rb_data_type_t grpc_channel_data_type = {
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
NULL,
|
136
|
-
NULL,
|
110
|
+
static rb_data_type_t grpc_channel_data_type = {
|
111
|
+
"grpc_channel",
|
112
|
+
{grpc_rb_channel_mark, grpc_rb_channel_free, GRPC_RB_MEMSIZE_UNAVAILABLE,
|
113
|
+
{NULL, NULL}},
|
114
|
+
NULL, NULL,
|
137
115
|
#ifdef RUBY_TYPED_FREE_IMMEDIATELY
|
138
|
-
|
116
|
+
RUBY_TYPED_FREE_IMMEDIATELY
|
139
117
|
#endif
|
140
118
|
};
|
141
119
|
|
@@ -170,7 +148,6 @@ static VALUE grpc_rb_channel_init(int argc, VALUE *argv, VALUE self) {
|
|
170
148
|
rb_scan_args(argc, argv, "3", &target, &channel_args, &credentials);
|
171
149
|
|
172
150
|
TypedData_Get_Struct(self, grpc_rb_channel, &grpc_channel_data_type, wrapper);
|
173
|
-
wrapper->mu_init_done = 0;
|
174
151
|
target_chars = StringValueCStr(target);
|
175
152
|
grpc_rb_hash_convert_to_channel_args(channel_args, &args);
|
176
153
|
if (TYPE(credentials) == T_SYMBOL) {
|
@@ -185,27 +162,6 @@ static VALUE grpc_rb_channel_init(int argc, VALUE *argv, VALUE self) {
|
|
185
162
|
creds = grpc_rb_get_wrapped_channel_credentials(credentials);
|
186
163
|
ch = grpc_secure_channel_create(creds, target_chars, &args, NULL);
|
187
164
|
}
|
188
|
-
|
189
|
-
GPR_ASSERT(ch);
|
190
|
-
|
191
|
-
wrapper->wrapped = ch;
|
192
|
-
|
193
|
-
gpr_mu_init(&wrapper->channel_mu);
|
194
|
-
gpr_cv_init(&wrapper->channel_cv);
|
195
|
-
wrapper->mu_init_done = 1;
|
196
|
-
|
197
|
-
gpr_mu_lock(&wrapper->channel_mu);
|
198
|
-
wrapper->abort_watch_connectivity_state = 0;
|
199
|
-
wrapper->current_connectivity_state = grpc_channel_check_connectivity_state(wrapper->wrapped, 0);
|
200
|
-
wrapper->safe_to_destroy = 0;
|
201
|
-
wrapper->request_safe_destroy = 0;
|
202
|
-
|
203
|
-
gpr_cv_broadcast(&wrapper->channel_cv);
|
204
|
-
gpr_mu_unlock(&wrapper->channel_mu);
|
205
|
-
|
206
|
-
|
207
|
-
grpc_rb_channel_try_register_connection_polling(wrapper);
|
208
|
-
|
209
165
|
if (args.args != NULL) {
|
210
166
|
xfree(args.args); /* Allocated by grpc_rb_hash_convert_to_channel_args */
|
211
167
|
}
|
@@ -216,28 +172,25 @@ static VALUE grpc_rb_channel_init(int argc, VALUE *argv, VALUE self) {
|
|
216
172
|
}
|
217
173
|
rb_ivar_set(self, id_target, target);
|
218
174
|
wrapper->wrapped = ch;
|
175
|
+
wrapper->queue = grpc_completion_queue_create(NULL);
|
219
176
|
return self;
|
220
177
|
}
|
221
178
|
|
222
179
|
/*
|
223
180
|
call-seq:
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
Indicates the current state of the channel, whose value is one of the
|
228
|
-
constants defined in GRPC::Core::ConnectivityStates.
|
181
|
+
insecure_channel = Channel:new("myhost:8080", {'arg1': 'value1'})
|
182
|
+
creds = ...
|
183
|
+
secure_channel = Channel:new("myhost:443", {'arg1': 'value1'}, creds)
|
229
184
|
|
230
|
-
|
185
|
+
Creates channel instances. */
|
231
186
|
static VALUE grpc_rb_channel_get_connectivity_state(int argc, VALUE *argv,
|
232
187
|
VALUE self) {
|
233
|
-
VALUE
|
234
|
-
int grpc_try_to_connect = 0;
|
188
|
+
VALUE try_to_connect = Qfalse;
|
235
189
|
grpc_rb_channel *wrapper = NULL;
|
236
190
|
grpc_channel *ch = NULL;
|
237
191
|
|
238
192
|
/* "01" == 0 mandatory args, 1 (try_to_connect) is optional */
|
239
|
-
rb_scan_args(argc, argv, "01",
|
240
|
-
grpc_try_to_connect = RTEST(try_to_connect_param) ? 1 : 0;
|
193
|
+
rb_scan_args(argc, argv, "01", try_to_connect);
|
241
194
|
|
242
195
|
TypedData_Get_Struct(self, grpc_rb_channel, &grpc_channel_data_type, wrapper);
|
243
196
|
ch = wrapper->wrapped;
|
@@ -245,88 +198,57 @@ static VALUE grpc_rb_channel_get_connectivity_state(int argc, VALUE *argv,
|
|
245
198
|
rb_raise(rb_eRuntimeError, "closed!");
|
246
199
|
return Qnil;
|
247
200
|
}
|
248
|
-
return
|
201
|
+
return NUM2LONG(
|
202
|
+
grpc_channel_check_connectivity_state(ch, (int)try_to_connect));
|
249
203
|
}
|
250
204
|
|
251
|
-
|
252
|
-
grpc_rb_channel *wrapper;
|
253
|
-
gpr_timespec deadline;
|
254
|
-
int last_state;
|
255
|
-
} watch_state_stack;
|
256
|
-
|
257
|
-
static void *watch_channel_state_without_gvl(void *arg) {
|
258
|
-
watch_state_stack *stack = (watch_state_stack*)arg;
|
259
|
-
gpr_timespec deadline = stack->deadline;
|
260
|
-
grpc_rb_channel *wrapper = stack->wrapper;
|
261
|
-
int last_state = stack->last_state;
|
262
|
-
void *return_value = (void*)0;
|
263
|
-
|
264
|
-
gpr_mu_lock(&wrapper->channel_mu);
|
265
|
-
while(wrapper->current_connectivity_state == last_state &&
|
266
|
-
!wrapper->request_safe_destroy &&
|
267
|
-
!wrapper->safe_to_destroy &&
|
268
|
-
!wrapper->abort_watch_connectivity_state &&
|
269
|
-
gpr_time_cmp(deadline, gpr_now(GPR_CLOCK_REALTIME)) > 0) {
|
270
|
-
gpr_cv_wait(&wrapper->channel_cv, &wrapper->channel_mu, deadline);
|
271
|
-
}
|
272
|
-
if (wrapper->current_connectivity_state != last_state) {
|
273
|
-
return_value = (void*)1;
|
274
|
-
}
|
275
|
-
gpr_mu_unlock(&wrapper->channel_mu);
|
205
|
+
/* Watch for a change in connectivity state.
|
276
206
|
|
277
|
-
|
278
|
-
|
207
|
+
Once the channel connectivity state is different from the last observed
|
208
|
+
state, tag will be enqueued on cq with success=1
|
279
209
|
|
280
|
-
|
281
|
-
|
282
|
-
gpr_log(GPR_DEBUG, "GRPC_RUBY: watch channel state unblocking func called");
|
283
|
-
gpr_mu_lock(&wrapper->channel_mu);
|
284
|
-
wrapper->abort_watch_connectivity_state = 1;
|
285
|
-
gpr_cv_broadcast(&wrapper->channel_cv);
|
286
|
-
gpr_mu_unlock(&wrapper->channel_mu);
|
287
|
-
}
|
288
|
-
|
289
|
-
/* Wait until the channel's connectivity state becomes different from
|
290
|
-
* "last_state", or "deadline" expires.
|
291
|
-
* Returns true if the the channel's connectivity state becomes
|
292
|
-
* different from "last_state" within "deadline".
|
293
|
-
* Returns false if "deadline" expires before the channel's connectivity
|
294
|
-
* state changes from "last_state".
|
295
|
-
* */
|
210
|
+
If deadline expires BEFORE the state is changed, tag will be enqueued on
|
211
|
+
the completion queue with success=0 */
|
296
212
|
static VALUE grpc_rb_channel_watch_connectivity_state(VALUE self,
|
297
213
|
VALUE last_state,
|
298
214
|
VALUE deadline) {
|
299
215
|
grpc_rb_channel *wrapper = NULL;
|
300
|
-
|
301
|
-
|
216
|
+
grpc_channel *ch = NULL;
|
217
|
+
grpc_completion_queue *cq = NULL;
|
302
218
|
|
303
|
-
|
219
|
+
void *tag = wrapper;
|
304
220
|
|
305
|
-
|
221
|
+
grpc_event event;
|
222
|
+
|
223
|
+
TypedData_Get_Struct(self, grpc_rb_channel, &grpc_channel_data_type, wrapper);
|
224
|
+
ch = wrapper->wrapped;
|
225
|
+
cq = wrapper->queue;
|
226
|
+
if (ch == NULL) {
|
306
227
|
rb_raise(rb_eRuntimeError, "closed!");
|
307
228
|
return Qnil;
|
308
229
|
}
|
230
|
+
grpc_channel_watch_connectivity_state(
|
231
|
+
ch,
|
232
|
+
(grpc_connectivity_state)NUM2LONG(last_state),
|
233
|
+
grpc_rb_time_timeval(deadline, /* absolute time */ 0),
|
234
|
+
cq,
|
235
|
+
tag);
|
309
236
|
|
310
|
-
|
311
|
-
|
312
|
-
return Qnil;
|
313
|
-
}
|
237
|
+
event = rb_completion_queue_pluck(cq, tag,
|
238
|
+
gpr_inf_future(GPR_CLOCK_REALTIME), NULL);
|
314
239
|
|
315
|
-
|
316
|
-
stack.deadline = grpc_rb_time_timeval(deadline, 0);
|
317
|
-
stack.last_state = NUM2LONG(last_state);
|
318
|
-
out = rb_thread_call_without_gvl(watch_channel_state_without_gvl, &stack, watch_channel_state_unblocking_func, wrapper);
|
319
|
-
if (out) {
|
240
|
+
if (event.success) {
|
320
241
|
return Qtrue;
|
242
|
+
} else {
|
243
|
+
return Qfalse;
|
321
244
|
}
|
322
|
-
return Qfalse;
|
323
245
|
}
|
324
246
|
|
325
247
|
/* Create a call given a grpc_channel, in order to call method. The request
|
326
248
|
is not sent until grpc_call_invoke is called. */
|
327
|
-
static VALUE grpc_rb_channel_create_call(VALUE self, VALUE parent,
|
328
|
-
VALUE
|
329
|
-
VALUE deadline) {
|
249
|
+
static VALUE grpc_rb_channel_create_call(VALUE self, VALUE parent,
|
250
|
+
VALUE mask, VALUE method,
|
251
|
+
VALUE host, VALUE deadline) {
|
330
252
|
VALUE res = Qnil;
|
331
253
|
grpc_rb_channel *wrapper = NULL;
|
332
254
|
grpc_call *call = NULL;
|
@@ -337,11 +259,10 @@ static VALUE grpc_rb_channel_create_call(VALUE self, VALUE parent, VALUE mask,
|
|
337
259
|
grpc_slice method_slice;
|
338
260
|
grpc_slice host_slice;
|
339
261
|
grpc_slice *host_slice_ptr = NULL;
|
340
|
-
char
|
262
|
+
char* tmp_str = NULL;
|
341
263
|
|
342
264
|
if (host != Qnil) {
|
343
|
-
host_slice =
|
344
|
-
grpc_slice_from_copied_buffer(RSTRING_PTR(host), RSTRING_LEN(host));
|
265
|
+
host_slice = grpc_slice_from_copied_buffer(RSTRING_PTR(host), RSTRING_LEN(host));
|
345
266
|
host_slice_ptr = &host_slice;
|
346
267
|
}
|
347
268
|
if (mask != Qnil) {
|
@@ -359,18 +280,17 @@ static VALUE grpc_rb_channel_create_call(VALUE self, VALUE parent, VALUE mask,
|
|
359
280
|
return Qnil;
|
360
281
|
}
|
361
282
|
|
362
|
-
method_slice =
|
363
|
-
grpc_slice_from_copied_buffer(RSTRING_PTR(method), RSTRING_LEN(method));
|
283
|
+
method_slice = grpc_slice_from_copied_buffer(RSTRING_PTR(method), RSTRING_LEN(method));
|
364
284
|
|
365
285
|
call = grpc_channel_create_call(ch, parent_call, flags, cq, method_slice,
|
366
|
-
host_slice_ptr,
|
367
|
-
|
368
|
-
|
369
|
-
NULL);
|
286
|
+
host_slice_ptr, grpc_rb_time_timeval(
|
287
|
+
deadline,
|
288
|
+
/* absolute time */ 0), NULL);
|
370
289
|
|
371
290
|
if (call == NULL) {
|
372
291
|
tmp_str = grpc_slice_to_c_string(method_slice);
|
373
|
-
rb_raise(rb_eRuntimeError, "cannot create call with method %s",
|
292
|
+
rb_raise(rb_eRuntimeError, "cannot create call with method %s",
|
293
|
+
tmp_str);
|
374
294
|
return Qnil;
|
375
295
|
}
|
376
296
|
|
@@ -387,6 +307,7 @@ static VALUE grpc_rb_channel_create_call(VALUE self, VALUE parent, VALUE mask,
|
|
387
307
|
return res;
|
388
308
|
}
|
389
309
|
|
310
|
+
|
390
311
|
/* Closes the channel, calling it's destroy method */
|
391
312
|
static VALUE grpc_rb_channel_destroy(VALUE self) {
|
392
313
|
grpc_rb_channel *wrapper = NULL;
|
@@ -395,18 +316,19 @@ static VALUE grpc_rb_channel_destroy(VALUE self) {
|
|
395
316
|
TypedData_Get_Struct(self, grpc_rb_channel, &grpc_channel_data_type, wrapper);
|
396
317
|
ch = wrapper->wrapped;
|
397
318
|
if (ch != NULL) {
|
398
|
-
|
319
|
+
grpc_channel_destroy(ch);
|
399
320
|
wrapper->wrapped = NULL;
|
400
321
|
}
|
401
322
|
|
402
323
|
return Qnil;
|
403
324
|
}
|
404
325
|
|
326
|
+
|
405
327
|
/* Called to obtain the target that this channel accesses. */
|
406
328
|
static VALUE grpc_rb_channel_get_target(VALUE self) {
|
407
329
|
grpc_rb_channel *wrapper = NULL;
|
408
330
|
VALUE res = Qnil;
|
409
|
-
char
|
331
|
+
char* target = NULL;
|
410
332
|
|
411
333
|
TypedData_Get_Struct(self, grpc_rb_channel, &grpc_channel_data_type, wrapper);
|
412
334
|
target = grpc_channel_get_target(wrapper->wrapped);
|
@@ -416,122 +338,10 @@ static VALUE grpc_rb_channel_get_target(VALUE self) {
|
|
416
338
|
return res;
|
417
339
|
}
|
418
340
|
|
419
|
-
// Either start polling channel connection state or signal that it's free to
|
420
|
-
// destroy.
|
421
|
-
// Not safe to call while a channel's connection state is polled.
|
422
|
-
static void grpc_rb_channel_try_register_connection_polling(
|
423
|
-
grpc_rb_channel *wrapper) {
|
424
|
-
grpc_connectivity_state conn_state;
|
425
|
-
gpr_timespec sleep_time = gpr_time_add(
|
426
|
-
gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis(20, GPR_TIMESPAN));
|
427
|
-
|
428
|
-
GPR_ASSERT(wrapper);
|
429
|
-
GPR_ASSERT(wrapper->wrapped);
|
430
|
-
gpr_mu_lock(&wrapper->channel_mu);
|
431
|
-
if (wrapper->request_safe_destroy) {
|
432
|
-
wrapper->safe_to_destroy = 1;
|
433
|
-
gpr_cv_broadcast(&wrapper->channel_cv);
|
434
|
-
gpr_mu_unlock(&wrapper->channel_mu);
|
435
|
-
return;
|
436
|
-
}
|
437
|
-
gpr_mu_lock(&global_connection_polling_mu);
|
438
|
-
|
439
|
-
conn_state = grpc_channel_check_connectivity_state(wrapper->wrapped, 0);
|
440
|
-
if (conn_state != wrapper->current_connectivity_state) {
|
441
|
-
wrapper->current_connectivity_state = conn_state;
|
442
|
-
gpr_cv_broadcast(&wrapper->channel_cv);
|
443
|
-
}
|
444
|
-
// avoid posting work to the channel polling cq if it's been shutdown
|
445
|
-
if (!abort_channel_polling && conn_state != GRPC_CHANNEL_SHUTDOWN) {
|
446
|
-
grpc_channel_watch_connectivity_state(
|
447
|
-
wrapper->wrapped, conn_state, sleep_time, channel_polling_cq, wrapper);
|
448
|
-
} else {
|
449
|
-
wrapper->safe_to_destroy = 1;
|
450
|
-
gpr_cv_broadcast(&wrapper->channel_cv);
|
451
|
-
}
|
452
|
-
gpr_mu_unlock(&global_connection_polling_mu);
|
453
|
-
gpr_mu_unlock(&wrapper->channel_mu);
|
454
|
-
}
|
455
|
-
|
456
|
-
// Note requires wrapper->wrapped, wrapper->channel_mu/cv initialized
|
457
|
-
static void grpc_rb_channel_safe_destroy(grpc_rb_channel *wrapper) {
|
458
|
-
gpr_mu_lock(&wrapper->channel_mu);
|
459
|
-
wrapper->request_safe_destroy = 1;
|
460
|
-
|
461
|
-
while (!wrapper->safe_to_destroy) {
|
462
|
-
gpr_cv_wait(&wrapper->channel_cv, &wrapper->channel_mu,
|
463
|
-
gpr_inf_future(GPR_CLOCK_REALTIME));
|
464
|
-
}
|
465
|
-
GPR_ASSERT(wrapper->safe_to_destroy);
|
466
|
-
gpr_mu_unlock(&wrapper->channel_mu);
|
467
|
-
|
468
|
-
grpc_channel_destroy(wrapper->wrapped);
|
469
|
-
}
|
470
|
-
|
471
|
-
// Note this loop breaks out with a single call of
|
472
|
-
// "grpc_rb_event_unblocking_func".
|
473
|
-
// This assumes that a ruby call the unblocking func
|
474
|
-
// indicates process shutdown.
|
475
|
-
// In the worst case, this stops polling channel connectivity
|
476
|
-
// early and falls back to current behavior.
|
477
|
-
static void *run_poll_channels_loop_no_gil(void *arg) {
|
478
|
-
grpc_event event;
|
479
|
-
(void)arg;
|
480
|
-
for (;;) {
|
481
|
-
event = grpc_completion_queue_next(
|
482
|
-
channel_polling_cq, gpr_inf_future(GPR_CLOCK_REALTIME), NULL);
|
483
|
-
if (event.type == GRPC_QUEUE_SHUTDOWN) {
|
484
|
-
break;
|
485
|
-
}
|
486
|
-
if (event.type == GRPC_OP_COMPLETE) {
|
487
|
-
grpc_rb_channel_try_register_connection_polling((grpc_rb_channel *)event.tag);
|
488
|
-
}
|
489
|
-
}
|
490
|
-
grpc_completion_queue_destroy(channel_polling_cq);
|
491
|
-
gpr_log(GPR_DEBUG, "GRPC_RUBY: run_poll_channels_loop_no_gil - exit connection polling loop");
|
492
|
-
return NULL;
|
493
|
-
}
|
494
|
-
|
495
|
-
// Notify the channel polling loop to cleanup and shutdown.
|
496
|
-
static void grpc_rb_event_unblocking_func(void *arg) {
|
497
|
-
(void)arg;
|
498
|
-
gpr_mu_lock(&global_connection_polling_mu);
|
499
|
-
gpr_log(GPR_DEBUG, "GRPC_RUBY: grpc_rb_event_unblocking_func - begin aborting connection polling");
|
500
|
-
abort_channel_polling = 1;
|
501
|
-
grpc_completion_queue_shutdown(channel_polling_cq);
|
502
|
-
gpr_mu_unlock(&global_connection_polling_mu);
|
503
|
-
}
|
504
|
-
|
505
|
-
// Poll channel connectivity states in background thread without the GIL.
|
506
|
-
static VALUE run_poll_channels_loop(VALUE arg) {
|
507
|
-
(void)arg;
|
508
|
-
gpr_log(GPR_DEBUG, "GRPC_RUBY: run_poll_channels_loop - create connection polling thread");
|
509
|
-
rb_thread_call_without_gvl(run_poll_channels_loop_no_gil, NULL,
|
510
|
-
grpc_rb_event_unblocking_func, NULL);
|
511
|
-
return Qnil;
|
512
|
-
}
|
513
|
-
|
514
|
-
/* Temporary fix for
|
515
|
-
* https://github.com/GoogleCloudPlatform/google-cloud-ruby/issues/899.
|
516
|
-
* Transports in idle channels can get destroyed. Normally c-core re-connects,
|
517
|
-
* but in grpc-ruby core never gets a thread until an RPC is made, because ruby
|
518
|
-
* only calls c-core's "completion_queu_pluck" API.
|
519
|
-
* This uses a global background thread that calls
|
520
|
-
* "completion_queue_next" on registered "watch_channel_connectivity_state"
|
521
|
-
* calls - so that c-core can reconnect if needed, when there aren't any RPC's.
|
522
|
-
* TODO(apolcyn) remove this when core handles new RPCs on dead connections.
|
523
|
-
*/
|
524
|
-
static void start_poll_channels_loop() {
|
525
|
-
channel_polling_cq = grpc_completion_queue_create(NULL);
|
526
|
-
gpr_mu_init(&global_connection_polling_mu);
|
527
|
-
abort_channel_polling = 0;
|
528
|
-
rb_thread_create(run_poll_channels_loop, NULL);
|
529
|
-
}
|
530
|
-
|
531
341
|
static void Init_grpc_propagate_masks() {
|
532
342
|
/* Constants representing call propagation masks in grpc.h */
|
533
|
-
VALUE grpc_rb_mPropagateMasks =
|
534
|
-
|
343
|
+
VALUE grpc_rb_mPropagateMasks = rb_define_module_under(
|
344
|
+
grpc_rb_mGrpcCore, "PropagateMasks");
|
535
345
|
rb_define_const(grpc_rb_mPropagateMasks, "DEADLINE",
|
536
346
|
UINT2NUM(GRPC_PROPAGATE_DEADLINE));
|
537
347
|
rb_define_const(grpc_rb_mPropagateMasks, "CENSUS_STATS_CONTEXT",
|
@@ -546,8 +356,8 @@ static void Init_grpc_propagate_masks() {
|
|
546
356
|
|
547
357
|
static void Init_grpc_connectivity_states() {
|
548
358
|
/* Constants representing call propagation masks in grpc.h */
|
549
|
-
VALUE grpc_rb_mConnectivityStates =
|
550
|
-
|
359
|
+
VALUE grpc_rb_mConnectivityStates = rb_define_module_under(
|
360
|
+
grpc_rb_mGrpcCore, "ConnectivityStates");
|
551
361
|
rb_define_const(grpc_rb_mConnectivityStates, "IDLE",
|
552
362
|
LONG2NUM(GRPC_CHANNEL_IDLE));
|
553
363
|
rb_define_const(grpc_rb_mConnectivityStates, "CONNECTING",
|
@@ -575,11 +385,12 @@ void Init_grpc_channel() {
|
|
575
385
|
|
576
386
|
/* Add ruby analogues of the Channel methods. */
|
577
387
|
rb_define_method(grpc_rb_cChannel, "connectivity_state",
|
578
|
-
grpc_rb_channel_get_connectivity_state,
|
388
|
+
grpc_rb_channel_get_connectivity_state,
|
389
|
+
-1);
|
579
390
|
rb_define_method(grpc_rb_cChannel, "watch_connectivity_state",
|
580
|
-
grpc_rb_channel_watch_connectivity_state,
|
581
|
-
rb_define_method(grpc_rb_cChannel, "create_call",
|
582
|
-
5);
|
391
|
+
grpc_rb_channel_watch_connectivity_state, 4);
|
392
|
+
rb_define_method(grpc_rb_cChannel, "create_call",
|
393
|
+
grpc_rb_channel_create_call, 5);
|
583
394
|
rb_define_method(grpc_rb_cChannel, "target", grpc_rb_channel_get_target, 0);
|
584
395
|
rb_define_method(grpc_rb_cChannel, "destroy", grpc_rb_channel_destroy, 0);
|
585
396
|
rb_define_alias(grpc_rb_cChannel, "close", "destroy");
|
@@ -597,7 +408,6 @@ void Init_grpc_channel() {
|
|
597
408
|
id_insecure_channel = rb_intern("this_channel_is_insecure");
|
598
409
|
Init_grpc_propagate_masks();
|
599
410
|
Init_grpc_connectivity_states();
|
600
|
-
start_poll_channels_loop();
|
601
411
|
}
|
602
412
|
|
603
413
|
/* Gets the wrapped channel from the ruby wrapper */
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/src/ruby/lib/grpc/grpc_c.so
CHANGED
Binary file
|
@@ -153,35 +153,6 @@ describe GRPC::Core::Channel do
|
|
153
153
|
end
|
154
154
|
end
|
155
155
|
|
156
|
-
describe '#connectivity_state' do
|
157
|
-
it 'returns an enum' do
|
158
|
-
ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
|
159
|
-
valid_states = [
|
160
|
-
GRPC::Core::ConnectivityStates::IDLE,
|
161
|
-
GRPC::Core::ConnectivityStates::CONNECTING,
|
162
|
-
GRPC::Core::ConnectivityStates::READY,
|
163
|
-
GRPC::Core::ConnectivityStates::TRANSIENT_FAILURE,
|
164
|
-
GRPC::Core::ConnectivityStates::FATAL_FAILURE
|
165
|
-
]
|
166
|
-
|
167
|
-
expect(valid_states).to include(ch.connectivity_state)
|
168
|
-
end
|
169
|
-
|
170
|
-
it 'returns an enum when trying to connect' do
|
171
|
-
ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
|
172
|
-
ch.connectivity_state(true)
|
173
|
-
valid_states = [
|
174
|
-
GRPC::Core::ConnectivityStates::IDLE,
|
175
|
-
GRPC::Core::ConnectivityStates::CONNECTING,
|
176
|
-
GRPC::Core::ConnectivityStates::READY,
|
177
|
-
GRPC::Core::ConnectivityStates::TRANSIENT_FAILURE,
|
178
|
-
GRPC::Core::ConnectivityStates::FATAL_FAILURE
|
179
|
-
]
|
180
|
-
|
181
|
-
expect(valid_states).to include(ch.connectivity_state)
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
156
|
describe '::SSL_TARGET' do
|
186
157
|
it 'is a symbol' do
|
187
158
|
expect(GRPC::Core::Channel::SSL_TARGET).to be_a(Symbol)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.5
|
5
5
|
platform: x86-linux
|
6
6
|
authors:
|
7
7
|
- gRPC Authors
|
8
8
|
autorequire:
|
9
9
|
bindir: src/ruby/bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google-protobuf
|
@@ -261,7 +261,6 @@ files:
|
|
261
261
|
- src/ruby/pb/test/server.rb
|
262
262
|
- src/ruby/spec/call_credentials_spec.rb
|
263
263
|
- src/ruby/spec/call_spec.rb
|
264
|
-
- src/ruby/spec/channel_connection_spec.rb
|
265
264
|
- src/ruby/spec/channel_credentials_spec.rb
|
266
265
|
- src/ruby/spec/channel_spec.rb
|
267
266
|
- src/ruby/spec/client_server_spec.rb
|
@@ -333,7 +332,6 @@ test_files:
|
|
333
332
|
- src/ruby/spec/time_consts_spec.rb
|
334
333
|
- src/ruby/spec/channel_credentials_spec.rb
|
335
334
|
- src/ruby/spec/call_credentials_spec.rb
|
336
|
-
- src/ruby/spec/channel_connection_spec.rb
|
337
335
|
- src/ruby/spec/server_spec.rb
|
338
336
|
- src/ruby/spec/error_sanity_spec.rb
|
339
337
|
- src/ruby/spec/compression_options_spec.rb
|
@@ -1,141 +0,0 @@
|
|
1
|
-
# Copyright 2015, Google Inc.
|
2
|
-
# All rights reserved.
|
3
|
-
#
|
4
|
-
# Redistribution and use in source and binary forms, with or without
|
5
|
-
# modification, are permitted provided that the following conditions are
|
6
|
-
# met:
|
7
|
-
#
|
8
|
-
# * Redistributions of source code must retain the above copyright
|
9
|
-
# notice, this list of conditions and the following disclaimer.
|
10
|
-
# * Redistributions in binary form must reproduce the above
|
11
|
-
# copyright notice, this list of conditions and the following disclaimer
|
12
|
-
# in the documentation and/or other materials provided with the
|
13
|
-
# distribution.
|
14
|
-
# * Neither the name of Google Inc. nor the names of its
|
15
|
-
# contributors may be used to endorse or promote products derived from
|
16
|
-
# this software without specific prior written permission.
|
17
|
-
#
|
18
|
-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
19
|
-
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
20
|
-
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
21
|
-
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
22
|
-
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
23
|
-
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
24
|
-
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
25
|
-
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
26
|
-
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
27
|
-
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
28
|
-
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
-
|
30
|
-
require 'grpc'
|
31
|
-
|
32
|
-
# A test message
|
33
|
-
class EchoMsg
|
34
|
-
def self.marshal(_o)
|
35
|
-
''
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.unmarshal(_o)
|
39
|
-
EchoMsg.new
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
# A test service with an echo implementation.
|
44
|
-
class EchoService
|
45
|
-
include GRPC::GenericService
|
46
|
-
rpc :an_rpc, EchoMsg, EchoMsg
|
47
|
-
attr_reader :received_md
|
48
|
-
|
49
|
-
def initialize(**kw)
|
50
|
-
@trailing_metadata = kw
|
51
|
-
@received_md = []
|
52
|
-
end
|
53
|
-
|
54
|
-
def an_rpc(req, call)
|
55
|
-
GRPC.logger.info('echo service received a request')
|
56
|
-
call.output_metadata.update(@trailing_metadata)
|
57
|
-
@received_md << call.metadata unless call.metadata.nil?
|
58
|
-
req
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
EchoStub = EchoService.rpc_stub_class
|
63
|
-
|
64
|
-
def start_server(port = 0)
|
65
|
-
@srv = GRPC::RpcServer.new
|
66
|
-
server_port = @srv.add_http2_port("localhost:#{port}", :this_port_is_insecure)
|
67
|
-
@srv.handle(EchoService)
|
68
|
-
@server_thd = Thread.new { @srv.run }
|
69
|
-
@srv.wait_till_running
|
70
|
-
server_port
|
71
|
-
end
|
72
|
-
|
73
|
-
def stop_server
|
74
|
-
expect(@srv.stopped?).to be(false)
|
75
|
-
@srv.stop
|
76
|
-
@server_thd.join
|
77
|
-
expect(@srv.stopped?).to be(true)
|
78
|
-
end
|
79
|
-
|
80
|
-
describe 'channel connection behavior' do
|
81
|
-
it 'the client channel handles temporary loss of a transport' do
|
82
|
-
port = start_server
|
83
|
-
stub = EchoStub.new("localhost:#{port}", :this_channel_is_insecure)
|
84
|
-
req = EchoMsg.new
|
85
|
-
expect(stub.an_rpc(req)).to be_a(EchoMsg)
|
86
|
-
stop_server
|
87
|
-
sleep 1
|
88
|
-
# TODO(apolcyn) grabbing the same port might fail, is this stable enough?
|
89
|
-
start_server(port)
|
90
|
-
expect(stub.an_rpc(req)).to be_a(EchoMsg)
|
91
|
-
stop_server
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'observably connects and reconnects to transient server' \
|
95
|
-
' when using the channel state API' do
|
96
|
-
port = start_server
|
97
|
-
ch = GRPC::Core::Channel.new("localhost:#{port}", {},
|
98
|
-
:this_channel_is_insecure)
|
99
|
-
|
100
|
-
expect(ch.connectivity_state).to be(GRPC::Core::ConnectivityStates::IDLE)
|
101
|
-
|
102
|
-
state = ch.connectivity_state(true)
|
103
|
-
|
104
|
-
count = 0
|
105
|
-
while count < 20 && state != GRPC::Core::ConnectivityStates::READY
|
106
|
-
ch.watch_connectivity_state(state, Time.now + 60)
|
107
|
-
state = ch.connectivity_state(true)
|
108
|
-
count += 1
|
109
|
-
end
|
110
|
-
|
111
|
-
expect(state).to be(GRPC::Core::ConnectivityStates::READY)
|
112
|
-
|
113
|
-
stop_server
|
114
|
-
|
115
|
-
state = ch.connectivity_state
|
116
|
-
|
117
|
-
count = 0
|
118
|
-
while count < 20 && state == GRPC::Core::ConnectivityStates::READY
|
119
|
-
ch.watch_connectivity_state(state, Time.now + 60)
|
120
|
-
state = ch.connectivity_state
|
121
|
-
count += 1
|
122
|
-
end
|
123
|
-
|
124
|
-
expect(state).to_not be(GRPC::Core::ConnectivityStates::READY)
|
125
|
-
|
126
|
-
start_server(port)
|
127
|
-
|
128
|
-
state = ch.connectivity_state(true)
|
129
|
-
|
130
|
-
count = 0
|
131
|
-
while count < 20 && state != GRPC::Core::ConnectivityStates::READY
|
132
|
-
ch.watch_connectivity_state(state, Time.now + 60)
|
133
|
-
state = ch.connectivity_state(true)
|
134
|
-
count += 1
|
135
|
-
end
|
136
|
-
|
137
|
-
expect(state).to be(GRPC::Core::ConnectivityStates::READY)
|
138
|
-
|
139
|
-
stop_server
|
140
|
-
end
|
141
|
-
end
|