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