Move timeout handling into the extension

pull/1188/head
Tim Emiola 10 years ago
parent c8b55a3a31
commit 89cc87359f
  1. 11
      src/ruby/ext/grpc/rb_call.c
  2. 6
      src/ruby/ext/grpc/rb_call.h
  3. 4
      src/ruby/lib/grpc/errors.rb
  4. 2
      src/ruby/lib/grpc/generic/rpc_desc.rb
  5. 2
      src/ruby/spec/generic/rpc_server_spec.rb

@ -556,6 +556,11 @@ static VALUE grpc_rb_call_run_batch(VALUE self, VALUE cqueue, VALUE tag,
return;
}
ev = grpc_rb_completion_queue_pluck_event(cqueue, tag, timeout);
if (ev == NULL) {
grpc_run_batch_stack_cleanup(&st);
rb_raise(rb_eOutOfTime, "grpc_call_start_batch timed out");
return;
}
if (ev->data.op_complete != GRPC_OP_OK) {
grpc_run_batch_stack_cleanup(&st);
rb_raise(rb_eCallError, "start_batch completion failed, (code=%d)",
@ -576,6 +581,10 @@ VALUE rb_cCall = Qnil;
operations; */
VALUE rb_eCallError = Qnil;
/* rb_eOutOfTime is the ruby class of the exception thrown to indicate
a timeout. */
VALUE rb_eOutOfTime = Qnil;
void Init_grpc_error_codes() {
/* Constants representing the error codes of grpc_call_error in grpc.h */
VALUE rb_RpcErrors = rb_define_module_under(rb_mGrpcCore, "RpcErrors");
@ -651,6 +660,8 @@ void Init_grpc_call() {
/* CallError inherits from Exception to signal that it is non-recoverable */
rb_eCallError =
rb_define_class_under(rb_mGrpcCore, "CallError", rb_eException);
rb_eOutOfTime =
rb_define_class_under(rb_mGrpcCore, "OutOfTime", rb_eException);
rb_cCall = rb_define_class_under(rb_mGrpcCore, "Call", rb_cObject);
rb_cMdAry = rb_define_class_under(rb_mGrpcCore, "MetadataArray",
rb_cObject);

@ -52,10 +52,14 @@ VALUE grpc_rb_md_ary_to_h(grpc_metadata_array *md_ary);
/* rb_cCall is the Call class whose instances proxy grpc_call. */
extern VALUE rb_cCall;
/* rb_cCallError is the ruby class of the exception thrown during call
/* rb_eCallError is the ruby class of the exception thrown during call
operations. */
extern VALUE rb_eCallError;
/* rb_eOutOfTime is the ruby class of the exception thrown to indicate
a timeout. */
extern VALUE rb_eOutOfTime;
/* Initializes the Call class. */
void Init_grpc_call();

@ -31,10 +31,6 @@ require 'grpc'
# GRPC contains the General RPC module.
module GRPC
# OutOfTime is an exception class that indicates that an RPC exceeded its
# deadline.
OutOfTime = Class.new(StandardError)
# BadStatus is an exception class that indicates that an error occurred at
# either end of a GRPC connection. When raised, it indicates that a status
# error should be returned to the other end of a GRPC connection; when

@ -90,7 +90,7 @@ module GRPC
# This is raised by GRPC internals but should rarely, if ever happen.
# Log it, but don't notify the other endpoint..
logger.warn("failed call: #{active_call}\n#{e}")
rescue OutOfTime
rescue Core::OutOfTime
# This is raised when active_call#method.call exceeeds the deadline
# event. Send a status of deadline exceeded
logger.warn("late call: #{active_call}")

@ -364,7 +364,7 @@ describe GRPC::RpcServer do
@srv.wait_till_running
req = EchoMsg.new
stub = SlowStub.new(@host, **@client_opts)
deadline = service.delay + 0.5 # wait for long enough
deadline = service.delay + 1.0 # wait for long enough
expect(stub.an_rpc(req, deadline, k1: 'v1', k2: 'v2')).to be_a(EchoMsg)
wanted_md = [{ 'k1' => 'v1', 'k2' => 'v2' }]
expect(service.received_md).to eq(wanted_md)

Loading…
Cancel
Save