forking_client_client.rb 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env ruby
  2. # Copyright 2015 gRPC authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # Prompted by and minimal repro of https://github.com/grpc/grpc/issues/10658
  16. require_relative './end2end_common'
  17. def main
  18. server_port = ''
  19. OptionParser.new do |opts|
  20. opts.on('--client_control_port=P', String) do
  21. STDERR.puts 'client control port not used'
  22. end
  23. opts.on('--server_port=P', String) do |p|
  24. server_port = p
  25. end
  26. end.parse!
  27. p = fork do
  28. stub = Echo::EchoServer::Stub.new("localhost:#{server_port}",
  29. :this_channel_is_insecure)
  30. stub.echo(Echo::EchoRequest.new(request: 'hello'))
  31. end
  32. begin
  33. Timeout.timeout(10) do
  34. Process.wait(p)
  35. end
  36. rescue Timeout::Error
  37. STDERR.puts "timeout waiting for forked process #{p}"
  38. Process.kill('SIGKILL', p)
  39. Process.wait(p)
  40. raise 'Timed out waiting for client process. ' \
  41. 'It likely hangs when using gRPC after loading it and then forking'
  42. end
  43. client_exit_code = $CHILD_STATUS
  44. fail "forked process failed #{client_exit_code}" if client_exit_code != 0
  45. end
  46. main