diff options
author | murgatroid99 <mlumish@google.com> | 2016-06-28 14:14:49 -0700 |
---|---|---|
committer | murgatroid99 <mlumish@google.com> | 2016-06-28 14:14:49 -0700 |
commit | 00338657d949f248e5b978b2c03769f9ae19b53b (patch) | |
tree | 6113b39b9119158645b8b7d562ebca0d52665e25 | |
parent | 67e2525892c57be3b20d517810c25a5e861cb515 (diff) |
Fix bug that occasionally caused a call to be deleted twice
-rw-r--r-- | src/ruby/ext/grpc/rb_call.c | 9 | ||||
-rw-r--r-- | src/ruby/lib/grpc/generic/bidi_call.rb | 18 |
2 files changed, 16 insertions, 11 deletions
diff --git a/src/ruby/ext/grpc/rb_call.c b/src/ruby/ext/grpc/rb_call.c index c1f5075b52..f62397e79f 100644 --- a/src/ruby/ext/grpc/rb_call.c +++ b/src/ruby/ext/grpc/rb_call.c @@ -94,8 +94,13 @@ typedef struct grpc_rb_call { } grpc_rb_call; static void destroy_call(grpc_rb_call *call) { - grpc_call_destroy(call->wrapped); - grpc_rb_completion_queue_destroy(call->queue); + /* Ensure that we only try to destroy the call once */ + if (call->wrapped != NULL) { + grpc_call_destroy(call->wrapped); + call->wrapped = NULL; + grpc_rb_completion_queue_destroy(call->queue); + call->queue = NULL; + } } /* Destroys a Call. */ diff --git a/src/ruby/lib/grpc/generic/bidi_call.rb b/src/ruby/lib/grpc/generic/bidi_call.rb index e2a026cacc..425dc3e519 100644 --- a/src/ruby/lib/grpc/generic/bidi_call.rb +++ b/src/ruby/lib/grpc/generic/bidi_call.rb @@ -161,7 +161,15 @@ module GRPC count += 1 payload = @marshal.call(req) # Fails if status already received - @call.run_batch(SEND_MESSAGE => payload) + begin + @call.run_batch(SEND_MESSAGE => payload) + rescue GRPC::Core::CallError => e + # This is almost definitely caused by a status arriving while still + # writing. Don't re-throw the error + GRPC.logger.warn('bidi-write-loop: ended with error') + GRPC.logger.warn(e) + break + end end GRPC.logger.debug("bidi-write-loop: #{count} writes done") if is_client @@ -173,14 +181,6 @@ module GRPC finished end GRPC.logger.debug('bidi-write-loop: finished') - rescue GRPC::Core::CallError => e - # This is almost definitely caused by a status arriving while still - # writing. Don't re-throw the error - GRPC.logger.warn('bidi-write-loop: ended with error') - GRPC.logger.warn(e) - notify_done - @writes_complete = true - finished rescue StandardError => e GRPC.logger.warn('bidi-write-loop: failed') GRPC.logger.warn(e) |