Merge pull request #15834 from ganmacs/ensure-that-cancelled-server_streamer-call-raise-cancell

GRPC::Cancelled should be occured when calling Enumrable#next on canceled call
pull/15852/head
apolcyn 7 years ago committed by GitHub
commit 24416c7a19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      src/ruby/lib/grpc/generic/active_call.rb
  2. 12
      src/ruby/spec/generic/client_stub_spec.rb

@ -322,18 +322,22 @@ module GRPC
# @return [Enumerator] if no block was given
def each_remote_read_then_finish
return enum_for(:each_remote_read_then_finish) unless block_given?
begin
loop do
resp = remote_read
if resp.nil? # the last response was received
receive_and_check_status
break
loop do
resp =
begin
remote_read
rescue GRPC::Core::CallError => e
GRPC.logger.warn("In each_remote_read_then_finish: #{e}")
nil
end
yield resp
end
ensure
set_input_stream_done
break if resp.nil? # the last response was received
yield resp
end
receive_and_check_status
ensure
set_input_stream_done
end
# request_response sends a request to a GRPC server, and returns the

@ -589,6 +589,18 @@ describe 'ClientStub' do # rubocop:disable Metrics/BlockLength
responses.each { |r| p r }
end
end
it 'raises GRPC::Cancelled after the call has been cancelled' do
server_port = create_test_server
host = "localhost:#{server_port}"
th = run_server_streamer(@sent_msg, @replys, @pass)
stub = GRPC::ClientStub.new(host, :this_channel_is_insecure)
resp = get_responses(stub, run_start_call_first: false)
expect(resp.next).to eq('reply_1')
@op.cancel
expect { resp.next }.to raise_error(GRPC::Cancelled)
th.join
end
end
end

Loading…
Cancel
Save