diff options
author | Tim Emiola <temiola@google.com> | 2015-08-28 16:57:28 -0700 |
---|---|---|
committer | Tim Emiola <temiola@google.com> | 2015-08-28 17:11:11 -0700 |
commit | 81d950a5a91d863547761bcf5647ae8ebfc72722 (patch) | |
tree | 635cc4abca574b9606fd9d6cc1a0e3aef02220b8 /src/ruby/lib | |
parent | 036bf58b281e4ff65ccc62ea68002a50ddb626cc (diff) |
Updates server shutdown handling
- ensures that servers cancels calls after the shutdown timeout
- uses an infinite timeout when request server calls
This two changes fix the issue where the server segfaults on shutdown.
Diffstat (limited to 'src/ruby/lib')
-rw-r--r-- | src/ruby/lib/grpc/generic/rpc_server.rb | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/ruby/lib/grpc/generic/rpc_server.rb b/src/ruby/lib/grpc/generic/rpc_server.rb index 67bf35ce02..38ea333413 100644 --- a/src/ruby/lib/grpc/generic/rpc_server.rb +++ b/src/ruby/lib/grpc/generic/rpc_server.rb @@ -277,10 +277,11 @@ module GRPC @stop_mutex.synchronize do @stopped = true end - @pool.stop deadline = from_relative_time(@poll_period) - + return if @server.close(@cq, deadline) + deadline = from_relative_time(@poll_period) @server.close(@cq, deadline) + @pool.stop end # determines if the server has been stopped @@ -383,7 +384,6 @@ module GRPC @pool.start @server.start loop_handle_server_calls - @running = false end # Sends UNAVAILABLE if there are too many unprocessed jobs @@ -414,14 +414,13 @@ module GRPC fail 'not running' unless @running loop_tag = Object.new until stopped? - deadline = from_relative_time(@poll_period) begin - an_rpc = @server.request_call(@cq, loop_tag, deadline) + an_rpc = @server.request_call(@cq, loop_tag, INFINITE_FUTURE) c = new_active_server_call(an_rpc) rescue Core::CallError, RuntimeError => e # these might happen for various reasonse. The correct behaviour of - # the server is to log them and continue. - GRPC.logger.warn("server call failed: #{e}") + # the server is to log them and continue, if it's not shutting down. + GRPC.logger.warn("server call failed: #{e}") unless stopped? next end unless c.nil? @@ -431,6 +430,8 @@ module GRPC end end end + @running = false + GRPC.logger.info("stopped: #{self}") end def new_active_server_call(an_rpc) |