grpc 1.7.3-x64-mingw32 → 1.8.0-x64-mingw32

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.

@@ -44,12 +44,12 @@ static VALUE id_insecure_server;
44
44
  /* grpc_rb_server wraps a grpc_server. */
45
45
  typedef struct grpc_rb_server {
46
46
  /* The actual server */
47
- grpc_server *wrapped;
48
- grpc_completion_queue *queue;
47
+ grpc_server* wrapped;
48
+ grpc_completion_queue* queue;
49
49
  gpr_atm shutdown_started;
50
50
  } grpc_rb_server;
51
51
 
52
- static void destroy_server(grpc_rb_server *server, gpr_timespec deadline) {
52
+ static void destroy_server(grpc_rb_server* server, gpr_timespec deadline) {
53
53
  grpc_event ev;
54
54
  // This can be started by app or implicitly by GC. Avoid a race between these.
55
55
  if (gpr_atm_full_fetch_add(&server->shutdown_started, (gpr_atm)1) == 0) {
@@ -70,13 +70,13 @@ static void destroy_server(grpc_rb_server *server, gpr_timespec deadline) {
70
70
  }
71
71
 
72
72
  /* Destroys server instances. */
73
- static void grpc_rb_server_free(void *p) {
74
- grpc_rb_server *svr = NULL;
73
+ static void grpc_rb_server_free(void* p) {
74
+ grpc_rb_server* svr = NULL;
75
75
  gpr_timespec deadline;
76
76
  if (p == NULL) {
77
77
  return;
78
78
  };
79
- svr = (grpc_rb_server *)p;
79
+ svr = (grpc_rb_server*)p;
80
80
 
81
81
  deadline = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
82
82
  gpr_time_from_seconds(2, GPR_TIMESPAN));
@@ -105,7 +105,7 @@ static const rb_data_type_t grpc_rb_server_data_type = {
105
105
 
106
106
  /* Allocates grpc_rb_server instances. */
107
107
  static VALUE grpc_rb_server_alloc(VALUE cls) {
108
- grpc_rb_server *wrapper = ALLOC(grpc_rb_server);
108
+ grpc_rb_server* wrapper = ALLOC(grpc_rb_server);
109
109
  wrapper->wrapped = NULL;
110
110
  wrapper->shutdown_started = (gpr_atm)0;
111
111
  return TypedData_Wrap_Struct(cls, &grpc_rb_server_data_type, wrapper);
@@ -117,9 +117,9 @@ static VALUE grpc_rb_server_alloc(VALUE cls) {
117
117
 
118
118
  Initializes server instances. */
119
119
  static VALUE grpc_rb_server_init(VALUE self, VALUE channel_args) {
120
- grpc_completion_queue *cq = NULL;
121
- grpc_rb_server *wrapper = NULL;
122
- grpc_server *srv = NULL;
120
+ grpc_completion_queue* cq = NULL;
121
+ grpc_rb_server* wrapper = NULL;
122
+ grpc_server* srv = NULL;
123
123
  grpc_channel_args args;
124
124
  MEMZERO(&args, grpc_channel_args, 1);
125
125
 
@@ -153,7 +153,7 @@ typedef struct request_call_stack {
153
153
 
154
154
  /* grpc_request_call_stack_init ensures the request_call_stack is properly
155
155
  * initialized */
156
- static void grpc_request_call_stack_init(request_call_stack *st) {
156
+ static void grpc_request_call_stack_init(request_call_stack* st) {
157
157
  MEMZERO(st, request_call_stack, 1);
158
158
  grpc_metadata_array_init(&st->md_ary);
159
159
  grpc_call_details_init(&st->details);
@@ -161,7 +161,7 @@ static void grpc_request_call_stack_init(request_call_stack *st) {
161
161
 
162
162
  /* grpc_request_call_stack_cleanup ensures the request_call_stack is properly
163
163
  * cleaned up */
164
- static void grpc_request_call_stack_cleanup(request_call_stack *st) {
164
+ static void grpc_request_call_stack_cleanup(request_call_stack* st) {
165
165
  grpc_metadata_array_destroy(&st->md_ary);
166
166
  grpc_call_details_destroy(&st->details);
167
167
  }
@@ -171,14 +171,14 @@ static void grpc_request_call_stack_cleanup(request_call_stack *st) {
171
171
 
172
172
  Requests notification of a new call on a server. */
173
173
  static VALUE grpc_rb_server_request_call(VALUE self) {
174
- grpc_rb_server *s = NULL;
175
- grpc_call *call = NULL;
174
+ grpc_rb_server* s = NULL;
175
+ grpc_call* call = NULL;
176
176
  grpc_event ev;
177
177
  grpc_call_error err;
178
178
  request_call_stack st;
179
179
  VALUE result;
180
- void *tag = (void *)&st;
181
- grpc_completion_queue *call_queue =
180
+ void* tag = (void*)&st;
181
+ grpc_completion_queue* call_queue =
182
182
  grpc_completion_queue_create_for_pluck(NULL);
183
183
  gpr_timespec deadline;
184
184
 
@@ -222,7 +222,7 @@ static VALUE grpc_rb_server_request_call(VALUE self) {
222
222
  }
223
223
 
224
224
  static VALUE grpc_rb_server_start(VALUE self) {
225
- grpc_rb_server *s = NULL;
225
+ grpc_rb_server* s = NULL;
226
226
  TypedData_Get_Struct(self, grpc_rb_server, &grpc_rb_server_data_type, s);
227
227
  if (s->wrapped == NULL) {
228
228
  rb_raise(rb_eRuntimeError, "destroyed!");
@@ -244,10 +244,10 @@ static VALUE grpc_rb_server_start(VALUE self) {
244
244
  server.destroy(timeout)
245
245
 
246
246
  Destroys server instances. */
247
- static VALUE grpc_rb_server_destroy(int argc, VALUE *argv, VALUE self) {
247
+ static VALUE grpc_rb_server_destroy(int argc, VALUE* argv, VALUE self) {
248
248
  VALUE timeout = Qnil;
249
249
  gpr_timespec deadline;
250
- grpc_rb_server *s = NULL;
250
+ grpc_rb_server* s = NULL;
251
251
 
252
252
  /* "01" == 0 mandatory args, 1 (timeout) is optional */
253
253
  rb_scan_args(argc, argv, "01", &timeout);
@@ -277,8 +277,8 @@ static VALUE grpc_rb_server_destroy(int argc, VALUE *argv, VALUE self) {
277
277
  Adds a http2 port to server */
278
278
  static VALUE grpc_rb_server_add_http2_port(VALUE self, VALUE port,
279
279
  VALUE rb_creds) {
280
- grpc_rb_server *s = NULL;
281
- grpc_server_credentials *creds = NULL;
280
+ grpc_rb_server* s = NULL;
281
+ grpc_server_credentials* creds = NULL;
282
282
  int recvd_port = 0;
283
283
 
284
284
  TypedData_Get_Struct(self, grpc_rb_server, &grpc_rb_server_data_type, s);
@@ -335,8 +335,8 @@ void Init_grpc_server() {
335
335
  }
336
336
 
337
337
  /* Gets the wrapped server from the ruby wrapper */
338
- grpc_server *grpc_rb_get_wrapped_server(VALUE v) {
339
- grpc_rb_server *wrapper = NULL;
338
+ grpc_server* grpc_rb_get_wrapped_server(VALUE v) {
339
+ grpc_rb_server* wrapper = NULL;
340
340
  TypedData_Get_Struct(v, grpc_rb_server, &grpc_rb_server_data_type, wrapper);
341
341
  return wrapper->wrapped;
342
342
  }
@@ -38,16 +38,16 @@ typedef struct grpc_rb_server_credentials {
38
38
  /* Holder of ruby objects involved in constructing the server credentials */
39
39
  VALUE mark;
40
40
  /* The actual server credentials */
41
- grpc_server_credentials *wrapped;
41
+ grpc_server_credentials* wrapped;
42
42
  } grpc_rb_server_credentials;
43
43
 
44
44
  /* Destroys the server credentials instances. */
45
- static void grpc_rb_server_credentials_free(void *p) {
46
- grpc_rb_server_credentials *wrapper = NULL;
45
+ static void grpc_rb_server_credentials_free(void* p) {
46
+ grpc_rb_server_credentials* wrapper = NULL;
47
47
  if (p == NULL) {
48
48
  return;
49
49
  };
50
- wrapper = (grpc_rb_server_credentials *)p;
50
+ wrapper = (grpc_rb_server_credentials*)p;
51
51
 
52
52
  /* Delete the wrapped object if the mark object is Qnil, which indicates that
53
53
  no other object is the actual owner. */
@@ -60,12 +60,12 @@ static void grpc_rb_server_credentials_free(void *p) {
60
60
  }
61
61
 
62
62
  /* Protects the mark object from GC */
63
- static void grpc_rb_server_credentials_mark(void *p) {
64
- grpc_rb_server_credentials *wrapper = NULL;
63
+ static void grpc_rb_server_credentials_mark(void* p) {
64
+ grpc_rb_server_credentials* wrapper = NULL;
65
65
  if (p == NULL) {
66
66
  return;
67
67
  }
68
- wrapper = (grpc_rb_server_credentials *)p;
68
+ wrapper = (grpc_rb_server_credentials*)p;
69
69
 
70
70
  /* If it's not already cleaned up, mark the mark object */
71
71
  if (wrapper->mark != Qnil) {
@@ -90,7 +90,7 @@ static const rb_data_type_t grpc_rb_server_credentials_data_type = {
90
90
 
91
91
  Provides safe initial defaults for the instance fields. */
92
92
  static VALUE grpc_rb_server_credentials_alloc(VALUE cls) {
93
- grpc_rb_server_credentials *wrapper = ALLOC(grpc_rb_server_credentials);
93
+ grpc_rb_server_credentials* wrapper = ALLOC(grpc_rb_server_credentials);
94
94
  wrapper->wrapped = NULL;
95
95
  wrapper->mark = Qnil;
96
96
  return TypedData_Wrap_Struct(cls, &grpc_rb_server_credentials_data_type,
@@ -128,9 +128,9 @@ static VALUE sym_private_key;
128
128
  static VALUE grpc_rb_server_credentials_init(VALUE self, VALUE pem_root_certs,
129
129
  VALUE pem_key_certs,
130
130
  VALUE force_client_auth) {
131
- grpc_rb_server_credentials *wrapper = NULL;
132
- grpc_server_credentials *creds = NULL;
133
- grpc_ssl_pem_key_cert_pair *key_cert_pairs = NULL;
131
+ grpc_rb_server_credentials* wrapper = NULL;
132
+ grpc_server_credentials* creds = NULL;
133
+ grpc_ssl_pem_key_cert_pair* key_cert_pairs = NULL;
134
134
  VALUE cert = Qnil;
135
135
  VALUE key = Qnil;
136
136
  VALUE key_cert = Qnil;
@@ -235,8 +235,8 @@ void Init_grpc_server_credentials() {
235
235
  }
236
236
 
237
237
  /* Gets the wrapped grpc_server_credentials from the ruby wrapper */
238
- grpc_server_credentials *grpc_rb_get_wrapped_server_credentials(VALUE v) {
239
- grpc_rb_server_credentials *wrapper = NULL;
238
+ grpc_server_credentials* grpc_rb_get_wrapped_server_credentials(VALUE v) {
239
+ grpc_rb_server_credentials* wrapper = NULL;
240
240
  TypedData_Get_Struct(v, grpc_rb_server_credentials,
241
241
  &grpc_rb_server_credentials_data_type, wrapper);
242
242
  return wrapper->wrapped;
@@ -92,9 +92,13 @@ module GRPC
92
92
  # Stops the jobs in the pool
93
93
  def stop
94
94
  GRPC.logger.info('stopping, will wait for all the workers to exit')
95
- schedule { throw :exit } while ready_for_work?
96
- @stop_mutex.synchronize do # wait @keep_alive for works to stop
95
+ @stop_mutex.synchronize do # wait @keep_alive seconds for workers to stop
97
96
  @stopped = true
97
+ loop do
98
+ break unless ready_for_work?
99
+ worker_queue = @ready_workers.pop
100
+ worker_queue << [proc { throw :exit }, []]
101
+ end
98
102
  @stop_cond.wait(@stop_mutex, @keep_alive) if @workers.size > 0
99
103
  end
100
104
  forcibly_stop_workers
@@ -138,7 +142,10 @@ module GRPC
138
142
  end
139
143
  # there shouldn't be any work given to this thread while its busy
140
144
  fail('received a task while busy') unless worker_queue.empty?
141
- @ready_workers << worker_queue
145
+ @stop_mutex.synchronize do
146
+ return if @stopped
147
+ @ready_workers << worker_queue
148
+ end
142
149
  end
143
150
  end
144
151
  end
@@ -186,8 +193,13 @@ module GRPC
186
193
  # * max_waiting_requests: Deprecated due to internal changes to the thread
187
194
  # pool. This is still an argument for compatibility but is ignored.
188
195
  #
189
- # * poll_period: when present, the server polls for new events with this
190
- # period
196
+ # * poll_period: The amount of time in seconds to wait for
197
+ # currently-serviced RPC's to finish before cancelling them when shutting
198
+ # down the server.
199
+ #
200
+ # * pool_keep_alive: The amount of time in seconds to wait
201
+ # for currently busy thread-pool threads to finish before
202
+ # forcing an abrupt exit to each thread.
191
203
  #
192
204
  # * connect_md_proc:
193
205
  # when non-nil is a proc for determining metadata to to send back the client
@@ -202,17 +214,18 @@ module GRPC
202
214
  # intercepting server handlers to provide extra functionality.
203
215
  # Interceptors are an EXPERIMENTAL API.
204
216
  #
205
- def initialize(pool_size:DEFAULT_POOL_SIZE,
206
- max_waiting_requests:DEFAULT_MAX_WAITING_REQUESTS,
207
- poll_period:DEFAULT_POLL_PERIOD,
208
- connect_md_proc:nil,
209
- server_args:{},
210
- interceptors:[])
217
+ def initialize(pool_size: DEFAULT_POOL_SIZE,
218
+ max_waiting_requests: DEFAULT_MAX_WAITING_REQUESTS,
219
+ poll_period: DEFAULT_POLL_PERIOD,
220
+ pool_keep_alive: GRPC::RpcServer::DEFAULT_POOL_SIZE,
221
+ connect_md_proc: nil,
222
+ server_args: {},
223
+ interceptors: [])
211
224
  @connect_md_proc = RpcServer.setup_connect_md_proc(connect_md_proc)
212
225
  @max_waiting_requests = max_waiting_requests
213
226
  @poll_period = poll_period
214
227
  @pool_size = pool_size
215
- @pool = Pool.new(@pool_size)
228
+ @pool = Pool.new(@pool_size, keep_alive: pool_keep_alive)
216
229
  @run_cond = ConditionVariable.new
217
230
  @run_mutex = Mutex.new
218
231
  # running_state can take 4 values: :not_started, :running, :stopping, and
Binary file
@@ -14,5 +14,5 @@
14
14
 
15
15
  # GRPC contains the General RPC module.
16
16
  module GRPC
17
- VERSION = '1.7.3'
17
+ VERSION = '1.8.0'
18
18
  end
@@ -48,6 +48,20 @@ module Grpc
48
48
  @status_mutex.synchronize { @statuses["#{service}"] = status }
49
49
  end
50
50
 
51
+ # Adds given health status for all given services
52
+ def set_status_for_services(status, *services)
53
+ @status_mutex.synchronize do
54
+ services.each { |service| @statuses["#{service}"] = status }
55
+ end
56
+ end
57
+
58
+ # Adds health status for each service given within hash
59
+ def add_statuses(service_statuses = {})
60
+ @status_mutex.synchronize do
61
+ service_statuses.each_pair { |service, status| @statuses["#{service}"] = status }
62
+ end
63
+ end
64
+
51
65
  # Clears the status for the given service.
52
66
  def clear_status(service)
53
67
  @status_mutex.synchronize { @statuses.delete("#{service}") }
@@ -99,6 +99,35 @@ describe Grpc::Health::Checker do
99
99
  end
100
100
  end
101
101
 
102
+ context 'method `add_statuses`' do
103
+ it 'should add status to each service' do
104
+ checker = Grpc::Health::Checker.new
105
+ checker.add_statuses(
106
+ 'service1' => ServingStatus::SERVING,
107
+ 'service2' => ServingStatus::NOT_SERVING
108
+ )
109
+ service1_health = checker.check(HCReq.new(service: 'service1'), nil)
110
+ service2_health = checker.check(HCReq.new(service: 'service2'), nil)
111
+ expect(service1_health).to eq(HCResp.new(status: ServingStatus::SERVING))
112
+ expect(service2_health).to eq(HCResp.new(status: ServingStatus::NOT_SERVING))
113
+ end
114
+ end
115
+
116
+ context 'method `set_status_for_services`' do
117
+ it 'should add given status to all given services' do
118
+ checker = Grpc::Health::Checker.new
119
+ checker.set_status_for_services(
120
+ ServingStatus::SERVING,
121
+ 'service1',
122
+ 'service2'
123
+ )
124
+ service1_health = checker.check(HCReq.new(service: 'service1'), nil)
125
+ service2_health = checker.check(HCReq.new(service: 'service2'), nil)
126
+ expect(service1_health).to eq(HCResp.new(status: ServingStatus::SERVING))
127
+ expect(service2_health).to eq(HCResp.new(status: ServingStatus::SERVING))
128
+ end
129
+ end
130
+
102
131
  context 'method `check`' do
103
132
  success_tests.each do |t|
104
133
  it "should fail with NOT_FOUND when #{t[:desc]}" do
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.7.3
4
+ version: 1.8.0
5
5
  platform: x64-mingw32
6
6
  authors:
7
7
  - gRPC Authors
8
8
  autorequire:
9
9
  bindir: src/ruby/bin
10
10
  cert_chain: []
11
- date: 2017-12-05 00:00:00.000000000 Z
11
+ date: 2017-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-protobuf