diff options
author | apolcyn <apolcyn@google.com> | 2018-06-22 15:27:58 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-22 15:27:58 -0700 |
commit | 24416c7a1960ec39ccf02075e2d7660bd496465e (patch) | |
tree | b68c3eb970b01f8b18224298446f6af7596a7227 | |
parent | 6cec581345b6f0c0b06256f2bc1ee0f842349150 (diff) | |
parent | c1b64e3493779c0e105b901d2a8f1fb8512d8bef (diff) |
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
-rw-r--r-- | src/ruby/lib/grpc/generic/active_call.rb | 24 | ||||
-rw-r--r-- | src/ruby/spec/generic/client_stub_spec.rb | 12 |
2 files changed, 26 insertions, 10 deletions
diff --git a/src/ruby/lib/grpc/generic/active_call.rb b/src/ruby/lib/grpc/generic/active_call.rb index 6e601bdc91..688726ef4a 100644 --- a/src/ruby/lib/grpc/generic/active_call.rb +++ b/src/ruby/lib/grpc/generic/active_call.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 diff --git a/src/ruby/spec/generic/client_stub_spec.rb b/src/ruby/spec/generic/client_stub_spec.rb index 3f878cc100..fbf594a655 100644 --- a/src/ruby/spec/generic/client_stub_spec.rb +++ b/src/ruby/spec/generic/client_stub_spec.rb @@ -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 |