grpc 1.2.2 → 1.2.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe74dce1192b418fae993739b5181b1b8a22d88d
4
- data.tar.gz: 6790711d2971f33ceedfc0fe635be38464a13d19
3
+ metadata.gz: 5a14992b3e2ffe604186dd6b68727f0c2961a890
4
+ data.tar.gz: 0e80b5086cac3c186c2d967d1cc9dbd4beab0e8c
5
5
  SHA512:
6
- metadata.gz: 05a49149ba143bc4af9765107be718daa22e7fa557da8c8d83a2d84a098a73c49808d8ea05b771d60369308d7101b7711e9d53f30bedc49aa4c2644ab5a7be12
7
- data.tar.gz: 8b6fb14eea4b7083c6d5c1a0dc03e2653128b09faa32380bf95f56ed7de09adeaa9a5acb0612923985dd219d1632b69c4f1192573cf9d85330184fc80c246ae4
6
+ metadata.gz: 4d1e6e8c3ebc6980fafb2bba4d2ae6cc823dc3b21eb270aed087d619e22b4d12e2d93bba6641e5e2a7f5f480c523f998009a655aefee3e5707c09ce8088162bb
7
+ data.tar.gz: 05321d6e3067952c8da50cbb3f8c6bab8bed177a7bae0e6f446f8d7eeaad3e0af6dbc3035f782d7790a78a48be6553b1b5ad8ff07a59fd5927e882ecf9f44bd5
data/Makefile CHANGED
@@ -412,8 +412,8 @@ Q = @
412
412
  endif
413
413
 
414
414
  CORE_VERSION = 3.0.0-dev
415
- CPP_VERSION = 1.2.2
416
- CSHARP_VERSION = 1.2.2
415
+ CPP_VERSION = 1.2.5
416
+ CSHARP_VERSION = 1.2.5
417
417
 
418
418
  CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES))
419
419
  CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS)
@@ -465,7 +465,7 @@ SHARED_VERSION_CORE = -3
465
465
  SHARED_VERSION_CPP = -1
466
466
  SHARED_VERSION_CSHARP = -1
467
467
  else ifeq ($(SYSTEM),Darwin)
468
- EXECUTABLE_SUFFIX =
468
+ EXECUTABLE_SUFFIX =
469
469
  SHARED_EXT_CORE = dylib
470
470
  SHARED_EXT_CPP = dylib
471
471
  SHARED_EXT_CSHARP = dylib
@@ -474,7 +474,7 @@ SHARED_VERSION_CORE =
474
474
  SHARED_VERSION_CPP =
475
475
  SHARED_VERSION_CSHARP =
476
476
  else
477
- EXECUTABLE_SUFFIX =
477
+ EXECUTABLE_SUFFIX =
478
478
  SHARED_EXT_CORE = so.$(CORE_VERSION)
479
479
  SHARED_EXT_CPP = so.$(CPP_VERSION)
480
480
  SHARED_EXT_CSHARP = so.$(CSHARP_VERSION)
@@ -4100,7 +4100,7 @@ $(LIBDIR)/$(CONFIG)/libgrpc++$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP): $(LIBGRPC+
4100
4100
  ifeq ($(SYSTEM),Darwin)
4101
4101
  $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name $(SHARED_PREFIX)grpc++$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) -dynamiclib -o $(LIBDIR)/$(CONFIG)/libgrpc++$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBGRPC++_OBJS) $(ZLIB_MERGE_LIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) -lgrpc
4102
4102
  else
4103
- $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,libgrpc++.so.3 -o $(LIBDIR)/$(CONFIG)/libgrpc++$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBGRPC++_OBJS) $(ZLIB_MERGE_LIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) -lgrpc
4103
+ $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,libgrpc++.so.1 -o $(LIBDIR)/$(CONFIG)/libgrpc++$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBGRPC++_OBJS) $(ZLIB_MERGE_LIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) -lgrpc
4104
4104
  $(Q) ln -sf $(SHARED_PREFIX)grpc++$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/libgrpc++$(SHARED_VERSION_CPP).so.1
4105
4105
  $(Q) ln -sf $(SHARED_PREFIX)grpc++$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/libgrpc++$(SHARED_VERSION_CPP).so
4106
4106
  endif
@@ -4491,7 +4491,7 @@ $(LIBDIR)/$(CONFIG)/libgrpc++_cronet$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP): $(L
4491
4491
  ifeq ($(SYSTEM),Darwin)
4492
4492
  $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name $(SHARED_PREFIX)grpc++_cronet$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) -dynamiclib -o $(LIBDIR)/$(CONFIG)/libgrpc++_cronet$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBGRPC++_CRONET_OBJS) $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE) $(ZLIB_MERGE_LIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) -lgpr -lgrpc_cronet
4493
4493
  else
4494
- $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,libgrpc++_cronet.so.3 -o $(LIBDIR)/$(CONFIG)/libgrpc++_cronet$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBGRPC++_CRONET_OBJS) $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE) $(ZLIB_MERGE_LIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) -lgpr -lgrpc_cronet
4494
+ $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,libgrpc++_cronet.so.1 -o $(LIBDIR)/$(CONFIG)/libgrpc++_cronet$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBGRPC++_CRONET_OBJS) $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE) $(ZLIB_MERGE_LIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) -lgpr -lgrpc_cronet
4495
4495
  $(Q) ln -sf $(SHARED_PREFIX)grpc++_cronet$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/libgrpc++_cronet$(SHARED_VERSION_CPP).so.1
4496
4496
  $(Q) ln -sf $(SHARED_PREFIX)grpc++_cronet$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/libgrpc++_cronet$(SHARED_VERSION_CPP).so
4497
4497
  endif
@@ -4614,7 +4614,7 @@ $(LIBDIR)/$(CONFIG)/libgrpc++_reflection$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP):
4614
4614
  ifeq ($(SYSTEM),Darwin)
4615
4615
  $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name $(SHARED_PREFIX)grpc++_reflection$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) -dynamiclib -o $(LIBDIR)/$(CONFIG)/libgrpc++_reflection$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBGRPC++_REFLECTION_OBJS) $(ZLIB_MERGE_LIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) -lgrpc++
4616
4616
  else
4617
- $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,libgrpc++_reflection.so.3 -o $(LIBDIR)/$(CONFIG)/libgrpc++_reflection$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBGRPC++_REFLECTION_OBJS) $(ZLIB_MERGE_LIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) -lgrpc++
4617
+ $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,libgrpc++_reflection.so.1 -o $(LIBDIR)/$(CONFIG)/libgrpc++_reflection$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBGRPC++_REFLECTION_OBJS) $(ZLIB_MERGE_LIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) -lgrpc++
4618
4618
  $(Q) ln -sf $(SHARED_PREFIX)grpc++_reflection$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/libgrpc++_reflection$(SHARED_VERSION_CPP).so.1
4619
4619
  $(Q) ln -sf $(SHARED_PREFIX)grpc++_reflection$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/libgrpc++_reflection$(SHARED_VERSION_CPP).so
4620
4620
  endif
@@ -4970,7 +4970,7 @@ $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP): $
4970
4970
  ifeq ($(SYSTEM),Darwin)
4971
4971
  $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name $(SHARED_PREFIX)grpc++_unsecure$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) -dynamiclib -o $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBGRPC++_UNSECURE_OBJS) $(ZLIB_MERGE_LIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) -lgpr -lgrpc_unsecure
4972
4972
  else
4973
- $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,libgrpc++_unsecure.so.3 -o $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBGRPC++_UNSECURE_OBJS) $(ZLIB_MERGE_LIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) -lgpr -lgrpc_unsecure
4973
+ $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,libgrpc++_unsecure.so.1 -o $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBGRPC++_UNSECURE_OBJS) $(ZLIB_MERGE_LIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) -lgpr -lgrpc_unsecure
4974
4974
  $(Q) ln -sf $(SHARED_PREFIX)grpc++_unsecure$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure$(SHARED_VERSION_CPP).so.1
4975
4975
  $(Q) ln -sf $(SHARED_PREFIX)grpc++_unsecure$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure$(SHARED_VERSION_CPP).so
4976
4976
  endif
@@ -5560,7 +5560,7 @@ $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHA
5560
5560
  ifeq ($(SYSTEM),Darwin)
5561
5561
  $(Q) $(LD) $(LDFLAGS) $(if $(subst Linux,,$(SYSTEM)),,-Wl$(comma)-wrap$(comma)memcpy) -L$(LIBDIR)/$(CONFIG) -install_name $(SHARED_PREFIX)grpc_csharp_ext$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP) -dynamiclib -o $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP) $(LIBGRPC_CSHARP_EXT_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(ZLIB_MERGE_LIBS) $(LDLIBS)
5562
5562
  else
5563
- $(Q) $(LD) $(LDFLAGS) $(if $(subst Linux,,$(SYSTEM)),,-Wl$(comma)-wrap$(comma)memcpy) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,libgrpc_csharp_ext.so.3 -o $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP) $(LIBGRPC_CSHARP_EXT_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(ZLIB_MERGE_LIBS) $(LDLIBS)
5563
+ $(Q) $(LD) $(LDFLAGS) $(if $(subst Linux,,$(SYSTEM)),,-Wl$(comma)-wrap$(comma)memcpy) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,libgrpc_csharp_ext.so.1 -o $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP) $(LIBGRPC_CSHARP_EXT_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(ZLIB_MERGE_LIBS) $(LDLIBS)
5564
5564
  $(Q) ln -sf $(SHARED_PREFIX)grpc_csharp_ext$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP) $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext$(SHARED_VERSION_CSHARP).so.1
5565
5565
  $(Q) ln -sf $(SHARED_PREFIX)grpc_csharp_ext$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP) $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext$(SHARED_VERSION_CSHARP).so
5566
5566
  endif
@@ -214,14 +214,14 @@ static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx,
214
214
  if (strcmp(args->channel_args->args[i].key,
215
215
  GRPC_ARG_MAX_SEND_MESSAGE_LENGTH) == 0) {
216
216
  const grpc_integer_options options = {
217
- GRPC_DEFAULT_MAX_SEND_MESSAGE_LENGTH, 0, INT_MAX};
217
+ GRPC_DEFAULT_MAX_SEND_MESSAGE_LENGTH, -1, INT_MAX};
218
218
  chand->max_send_size =
219
219
  grpc_channel_arg_get_integer(&args->channel_args->args[i], options);
220
220
  }
221
221
  if (strcmp(args->channel_args->args[i].key,
222
222
  GRPC_ARG_MAX_RECEIVE_MESSAGE_LENGTH) == 0) {
223
223
  const grpc_integer_options options = {
224
- GRPC_DEFAULT_MAX_RECV_MESSAGE_LENGTH, 0, INT_MAX};
224
+ GRPC_DEFAULT_MAX_RECV_MESSAGE_LENGTH, -1, INT_MAX};
225
225
  chand->max_recv_size =
226
226
  grpc_channel_arg_get_integer(&args->channel_args->args[i], options);
227
227
  }
@@ -69,8 +69,9 @@ static int retry_named_port_failure(int status, request *r,
69
69
  int retry_status;
70
70
  uv_getaddrinfo_t *req = gpr_malloc(sizeof(uv_getaddrinfo_t));
71
71
  req->data = r;
72
+ r->port = svc[i][1];
72
73
  retry_status = uv_getaddrinfo(uv_default_loop(), req, getaddrinfo_cb,
73
- r->host, svc[i][1], r->hints);
74
+ r->host, r->port, r->hints);
74
75
  if (retry_status < 0 || getaddrinfo_cb == NULL) {
75
76
  // The callback will not be called
76
77
  gpr_free(req);
@@ -285,12 +285,11 @@ static void on_handshake_data_received_from_peer(grpc_exec_ctx *exec_ctx,
285
285
  if (num_left_overs > 0) {
286
286
  /* Put the leftovers in our buffer (ownership transfered). */
287
287
  if (has_left_overs_in_current_slice) {
288
- grpc_slice_buffer_add(
289
- &h->left_overs,
290
- grpc_slice_split_tail(&h->args->read_buffer->slices[i],
291
- consumed_slice_size));
288
+ grpc_slice tail = grpc_slice_split_tail(&h->args->read_buffer->slices[i],
289
+ consumed_slice_size);
290
+ grpc_slice_buffer_add(&h->left_overs, tail);
292
291
  /* split_tail above increments refcount. */
293
- grpc_slice_unref_internal(exec_ctx, h->args->read_buffer->slices[i]);
292
+ grpc_slice_unref_internal(exec_ctx, tail);
294
293
  }
295
294
  grpc_slice_buffer_addn(
296
295
  &h->left_overs, &h->args->read_buffer->slices[i + 1],
@@ -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
- int request_safe_destroy;
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
- grpc_rb_channel_safe_destroy(ch);
107
- ch->wrapped = NULL;
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 = {"grpc_channel",
131
- {grpc_rb_channel_mark,
132
- grpc_rb_channel_free,
133
- GRPC_RB_MEMSIZE_UNAVAILABLE,
134
- {NULL, NULL}},
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
- RUBY_TYPED_FREE_IMMEDIATELY
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
- ch.connectivity_state -> state
225
- ch.connectivity_state(true) -> state
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
- It also tries to connect if the chennel is idle in the second form. */
185
+ Creates channel instances. */
231
186
  static VALUE grpc_rb_channel_get_connectivity_state(int argc, VALUE *argv,
232
187
  VALUE self) {
233
- VALUE try_to_connect_param = Qfalse;
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", &try_to_connect_param);
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 LONG2NUM(grpc_channel_check_connectivity_state(wrapper->wrapped, grpc_try_to_connect));
201
+ return NUM2LONG(
202
+ grpc_channel_check_connectivity_state(ch, (int)try_to_connect));
249
203
  }
250
204
 
251
- typedef struct watch_state_stack {
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
- return return_value;
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
- static void watch_channel_state_unblocking_func(void *arg) {
281
- grpc_rb_channel *wrapper = (grpc_rb_channel*)arg;
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
- watch_state_stack stack;
301
- void* out;
216
+ grpc_channel *ch = NULL;
217
+ grpc_completion_queue *cq = NULL;
302
218
 
303
- TypedData_Get_Struct(self, grpc_rb_channel, &grpc_channel_data_type, wrapper);
219
+ void *tag = wrapper;
304
220
 
305
- if (wrapper->wrapped == NULL) {
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
- if (!FIXNUM_P(last_state)) {
311
- rb_raise(rb_eTypeError, "bad type for last_state. want a GRPC::Core::ChannelState constant");
312
- return Qnil;
313
- }
237
+ event = rb_completion_queue_pluck(cq, tag,
238
+ gpr_inf_future(GPR_CLOCK_REALTIME), NULL);
314
239
 
315
- stack.wrapper = wrapper;
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, VALUE mask,
328
- VALUE method, VALUE host,
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 *tmp_str = NULL;
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
- grpc_rb_time_timeval(deadline,
368
- /* absolute time */ 0),
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", tmp_str);
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
- grpc_rb_channel_safe_destroy(wrapper);
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 *target = NULL;
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
- rb_define_module_under(grpc_rb_mGrpcCore, "PropagateMasks");
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
- rb_define_module_under(grpc_rb_mGrpcCore, "ConnectivityStates");
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, -1);
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, 2);
581
- rb_define_method(grpc_rb_cChannel, "create_call", grpc_rb_channel_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 */
@@ -29,5 +29,5 @@
29
29
 
30
30
  # GRPC contains the General RPC module.
31
31
  module GRPC
32
- VERSION = '1.2.2'
32
+ VERSION = '1.2.5'
33
33
  end
@@ -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.2
4
+ version: 1.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - gRPC Authors
8
8
  autorequire:
9
9
  bindir: src/ruby/bin
10
10
  cert_chain: []
11
- date: 2017-04-05 00:00:00.000000000 Z
11
+ date: 2017-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-protobuf
@@ -787,7 +787,6 @@ files:
787
787
  - src/ruby/pb/test/server.rb
788
788
  - src/ruby/spec/call_credentials_spec.rb
789
789
  - src/ruby/spec/call_spec.rb
790
- - src/ruby/spec/channel_connection_spec.rb
791
790
  - src/ruby/spec/channel_credentials_spec.rb
792
791
  - src/ruby/spec/channel_spec.rb
793
792
  - src/ruby/spec/client_server_spec.rb
@@ -1296,7 +1295,6 @@ test_files:
1296
1295
  - src/ruby/spec/time_consts_spec.rb
1297
1296
  - src/ruby/spec/channel_credentials_spec.rb
1298
1297
  - src/ruby/spec/call_credentials_spec.rb
1299
- - src/ruby/spec/channel_connection_spec.rb
1300
1298
  - src/ruby/spec/server_spec.rb
1301
1299
  - src/ruby/spec/error_sanity_spec.rb
1302
1300
  - 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