Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gruf::Server doesn't handle signals #32

Closed
Parad0X opened this issue Oct 27, 2017 · 1 comment
Closed

Gruf::Server doesn't handle signals #32

Parad0X opened this issue Oct 27, 2017 · 1 comment

Comments

@Parad0X
Copy link

Parad0X commented Oct 27, 2017

It appears that all signal handling logic was removed from GRPC::RpcServer and server now simply crashes when process is killed:

Ctrl+C

I, [2017-10-27T12:59:43.326558 #87078]  INFO -- : Booting gRPC Server...
I, [2017-10-27T12:59:43.329951 #87078]  INFO -- : handling /grpc.health.v1.Health/Check with #<Method: Grpc::Health::V1::Health::Service#check>
^C
bundler: failed to load command: gruf (/Users/user/.rbenv/versions/2.4.1/bin/gruf)
Interrupt:
  /Users/user/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/grpc-1.6.6-universal-darwin/src/ruby/lib/grpc/generic/rpc_server.rb:370:in `request_call'
  /Users/user/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/grpc-1.6.6-universal-darwin/src/ruby/lib/grpc/generic/rpc_server.rb:370:in `loop_handle_server_calls'
  /Users/user/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/grpc-1.6.6-universal-darwin/src/ruby/lib/grpc/generic/rpc_server.rb:331:in `run'
  /Users/user/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gruf-2.0.1/lib/gruf/server.rb:63:in `start!'
  /Users/user/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gruf-2.0.1/bin/gruf:27:in `<top (required)>'
  /Users/user/.rbenv/versions/2.4.1/bin/gruf:22:in `load'
  /Users/user/.rbenv/versions/2.4.1/bin/gruf:22:in `<top (required)>

SIGTERM

I, [2017-10-27T12:59:43.326558 #87078]  INFO -- : Booting gRPC Server...
I, [2017-10-27T12:59:43.329951 #87078]  INFO -- : handling /grpc.health.v1.Health/Check with #<Method: Grpc::Health::V1::Health::Service#check>
bundler: failed to load command: gruf (/Users/user/.rbenv/versions/2.4.1/bin/gruf)
SignalException: SIGTERM
  /Users/user/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/grpc-1.6.6-universal-darwin/src/ruby/lib/grpc/generic/rpc_server.rb:370:in `request_call'

With this monkey-patch Ctrl+C and SIGTERM are handled properly.

Gruf::Server.class_eval do
  alias_method :orig_start!, :start!

  def start!
    orig_start!
  rescue Interrupt, SignalException, SystemExit
    logger.info { 'Shutting down gRPC server...' }
    server.stop
  end
end
I, [2017-10-27T12:59:43.326558 #87078]  INFO -- : Booting gRPC Server...
I, [2017-10-27T12:59:43.329951 #87078]  INFO -- : handling /grpc.health.v1.Health/Check with #
^C
I, [2017-10-27T13:01:14.288286 #87184]  INFO -- : Shutting down gRPC server...
I, [2017-10-27T13:01:14.288537 #87184]  INFO -- : stopping, will wait for all the workers to exit
I, [2017-10-27T13:01:14.290172 #87184]  INFO -- : schedule another job
I, [2017-10-27T13:01:14.292240 #87184]  INFO -- : stopped, all workers are shutdown

Can I submit a PR to rescue these exceptions in Gruf::Server so we can remove this patch from all of our services or am I missing something here?

@splittingred
Copy link
Member

Hey @Parad0X - apologies for the late reply, this seems to have slipped my inbox.

I've confirmed this - definitely needs addressing.

Definitely feel free to submit a PR if you want - I'll take a look tomorrow as well if you haven't gotten to it by then. Thanks for the detailed report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants