From 38281cfa59097c7006a6514fca791a7b50b7ff8a Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Tue, 3 May 2016 10:51:49 -0700 Subject: [PATCH 1/2] Ruby: improve server error handling, fix a reference error --- src/ruby/lib/grpc/generic/rpc_server.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/ruby/lib/grpc/generic/rpc_server.rb b/src/ruby/lib/grpc/generic/rpc_server.rb index 7f3a38a9f46..9a2af049471 100644 --- a/src/ruby/lib/grpc/generic/rpc_server.rb +++ b/src/ruby/lib/grpc/generic/rpc_server.rb @@ -332,15 +332,13 @@ module GRPC # the current thread to terminate it. def run_till_terminated GRPC.trap_signals - stopped = false t = Thread.new do run - stopped = true end + t.abort_on_exception = true wait_till_running - loop do + until running_state == :stopped sleep SIGNAL_CHECK_PERIOD - break if stopped break unless GRPC.handle_signals end stop @@ -416,7 +414,7 @@ module GRPC GRPC.logger.warn("NOT AVAILABLE: too many jobs_waiting: #{an_rpc}") noop = proc { |x| x } c = ActiveCall.new(an_rpc.call, @cq, noop, noop, an_rpc.deadline) - c.send_status(StatusCodes::RESOURCE_EXHAUSTED, '') + c.send_status(GRPC::Core::StatusCodes::RESOURCE_EXHAUSTED, '') nil end @@ -427,7 +425,7 @@ module GRPC GRPC.logger.warn("UNIMPLEMENTED: #{an_rpc}") noop = proc { |x| x } c = ActiveCall.new(an_rpc.call, @cq, noop, noop, an_rpc.deadline) - c.send_status(StatusCodes::UNIMPLEMENTED, '') + c.send_status(GRPC::Core::StatusCodes::UNIMPLEMENTED, '') nil end @@ -443,7 +441,12 @@ module GRPC unless active_call.nil? @pool.schedule(active_call) do |ac| c, mth = ac - rpc_descs[mth].run_server_method(c, rpc_handlers[mth]) + begin + rpc_descs[mth].run_server_method(c, rpc_handlers[mth]) + rescue StandardError => e + c.send_status(code = GRPC::Core::StatusCodes::INTERNAL, + details = "Server handler failed") + end end end rescue Core::CallError, RuntimeError => e From 59dfee880016e74edc9ebcadaf1ea624a4d457be Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Tue, 3 May 2016 11:33:25 -0700 Subject: [PATCH 2/2] Fixed rubocop issues with newest changes --- src/ruby/.rubocop.yml | 4 ++-- src/ruby/lib/grpc/generic/rpc_server.rb | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ruby/.rubocop.yml b/src/ruby/.rubocop.yml index d13ce426553..34bb4775435 100644 --- a/src/ruby/.rubocop.yml +++ b/src/ruby/.rubocop.yml @@ -11,10 +11,10 @@ AllCops: - 'pb/test/**/*' Metrics/CyclomaticComplexity: - Max: 8 + Max: 9 Metrics/PerceivedComplexity: - Max: 8 + Max: 9 Metrics/ClassLength: Max: 250 diff --git a/src/ruby/lib/grpc/generic/rpc_server.rb b/src/ruby/lib/grpc/generic/rpc_server.rb index 9a2af049471..a0f4071adc8 100644 --- a/src/ruby/lib/grpc/generic/rpc_server.rb +++ b/src/ruby/lib/grpc/generic/rpc_server.rb @@ -443,9 +443,9 @@ module GRPC c, mth = ac begin rpc_descs[mth].run_server_method(c, rpc_handlers[mth]) - rescue StandardError => e - c.send_status(code = GRPC::Core::StatusCodes::INTERNAL, - details = "Server handler failed") + rescue StandardError + c.send_status(GRPC::Core::StatusCodes::INTERNAL, + 'Server handler failed') end end end