1#!/usr/bin/env ruby 2 3# Copyright 2016 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# make sure that the client doesn't hang when channel is closed 18# explicitly while it's used 19 20require_relative './end2end_common' 21 22def main 23 STDERR.puts 'start server' 24 server_runner = ServerRunner.new(EchoServerImpl) 25 server_port = server_runner.run 26 STDERR.puts 'start client' 27 control_stub, client_pid = start_client('channel_closing_client.rb', 28 server_port) 29 # sleep to allow time for the client to get into 30 # the middle of a "watch connectivity state" call 31 sleep 3 32 33 begin 34 Timeout.timeout(20) do 35 loop do 36 begin 37 control_stub.shutdown(ClientControl::Void.new) 38 break 39 rescue GRPC::BadStatus => e 40 STDERR.puts "control_stub.shutdown RPC received error:|#{e}|. " \ 41 "This could mean that that child process e.g. isn't running yet, " \ 42 "so we'll retry the RPC" 43 end 44 end 45 Process.wait(client_pid) 46 end 47 rescue Timeout::Error 48 STDERR.puts "timeout wait for client pid #{client_pid}" 49 Process.kill('SIGKILL', client_pid) 50 Process.wait(client_pid) 51 STDERR.puts 'killed client child' 52 raise 'Timed out waiting for client process. It likely hangs when a ' \ 53 'channel is closed while connectivity is watched' 54 end 55 56 client_exit_code = $CHILD_STATUS 57 if client_exit_code != 0 58 fail "channel closing client failed, exit code #{client_exit_code}" 59 end 60 61 server_runner.stop 62end 63 64main 65