Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

feat: gracefully fail adding to the CompletionQueue after Shutdown #138

Merged
merged 3 commits into from
Jan 31, 2020
Merged

feat: gracefully fail adding to the CompletionQueue after Shutdown #138

merged 3 commits into from
Jan 31, 2020

Conversation

mr-salty
Copy link
Contributor

@mr-salty mr-salty commented Jan 27, 2020

The grpc CompletionQueue asserts if items are added to it after
Shutdown() is called. Make our CompletionQueue a little friendlier
by just failing those operations immediately.

Part of #129


This change is Reviewable

@mr-salty mr-salty requested a review from coryan January 27, 2020 23:56
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jan 27, 2020
@mr-salty
Copy link
Contributor Author

@coryan I made this a draft because I'm not sure it's the right approach, or if I'm doing the proper thing in async_read_stream_impl... but thought it was easier to discuss in code

@@ -54,8 +54,6 @@ class AsyncGrpcOperation : public AsyncOperation {
* Derived classes wrap the callbacks provided by the application and invoke
* the callback when this virtual member function is called.
*
* @param cq the completion queue sending the notification, this is useful in
* case the callback needs to retry the operation.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missed removing this in a prior PR

@codecov
Copy link

codecov bot commented Jan 28, 2020

Codecov Report

Merging #138 into master will decrease coverage by 0.14%.
The diff coverage is 84.05%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #138      +/-   ##
==========================================
- Coverage   95.81%   95.66%   -0.15%     
==========================================
  Files          83       83              
  Lines        3847     3900      +53     
==========================================
+ Hits         3686     3731      +45     
- Misses        161      169       +8
Impacted Files Coverage Δ
.../cloud/grpc_utils/internal/completion_queue_impl.h 89.47% <ø> (+10.52%) ⬆️
google/cloud/grpc_utils/completion_queue.cc 100% <100%> (ø) ⬆️
...cloud/grpc_utils/internal/completion_queue_impl.cc 86.48% <100%> (+0.97%) ⬆️
google/cloud/grpc_utils/completion_queue.h 100% <100%> (ø) ⬆️
...cloud/grpc_utils/internal/async_read_stream_impl.h 68.57% <80%> (-2.67%) ⬇️
google/cloud/grpc_utils/completion_queue_test.cc 93.58% <82.35%> (-4.22%) ⬇️
google/cloud/internal/future_then_impl.h 100% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0140b11...e152766. Read the comment docs.

Copy link
Contributor

@coryan coryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 5 of 5 files at r1.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@mr-salty mr-salty marked this pull request as ready for review January 28, 2020 17:09
@mr-salty
Copy link
Contributor Author


google/cloud/grpc_utils/internal/completion_queue_impl.h, line 105 at r1 (raw file):

Quoted 7 lines of code…
    if (!ok) {
      // This would mean a bug in gRPC. The documentation states that Finish()
      // always returns `true` for unary RPCs.
      promise_.set_value(::google::cloud::Status(
          google::cloud::StatusCode::kUnknown, "Finish() returned false"));
      return true;
    }

@coryan I did think about this - I think this can this be called now with ok == false, so maybe I should change the comment (and also change the status to kCancelled? WDYT?

I'll also see if I can write some tests to exercise this

Copy link
Contributor

@coryan coryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @mr-salty)


google/cloud/grpc_utils/internal/completion_queue_impl.h, line 105 at r1 (raw file):

Previously, mr-salty (Todd Derr) wrote…
    if (!ok) {
      // This would mean a bug in gRPC. The documentation states that Finish()
      // always returns `true` for unary RPCs.
      promise_.set_value(::google::cloud::Status(
          google::cloud::StatusCode::kUnknown, "Finish() returned false"));
      return true;
    }

@coryan I did think about this - I think this can this be called now with ok == false, so maybe I should change the comment (and also change the status to kCancelled? WDYT?

I'll also see if I can write some tests to exercise this

Removing the comment and changing the code to return kCancelled sounds like a good idea. Sorry I missed it.

For what it is worth, writing unit tests for this is a good idea, you need to mock "enough" of a gRPC-generated class to make it work though, it is sort of annoying, there is one such test in google-cloud-cpp (async_retry_unary_rpc_test.cc) that might be a good start.

The grpc `CompletionQueue` asserts if items are added to it after
`Shutdown()` is called. Make our `CompletionQueue` a little friendlier
by just failing those operations immediately.

Part of #129
Copy link
Contributor

@coryan coryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 1 of 1 files at r2.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @mr-salty)

Copy link
Contributor Author

@mr-salty mr-salty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 2 of 6 files reviewed, 1 unresolved discussion (waiting on @coryan)


google/cloud/grpc_utils/internal/completion_queue_impl.h, line 105 at r1 (raw file):

Previously, coryan (Carlos O'Ryan) wrote…

Removing the comment and changing the code to return kCancelled sounds like a good idea. Sorry I missed it.

For what it is worth, writing unit tests for this is a good idea, you need to mock "enough" of a gRPC-generated class to make it work though, it is sort of annoying, there is one such test in google-cloud-cpp (async_retry_unary_rpc_test.cc) that might be a good start.

I saw you added tests (thanks!) so I took what you did and added a new test, which uncovered a couple (or 3?) actual code bugs - PTAL

Copy link
Contributor

@coryan coryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 4 of 4 files at r3.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @mr-salty)


google/cloud/grpc_utils/internal/async_read_stream_impl.h, line 161 at r3 (raw file):

    void* tag = cq_->RegisterOperation(std::move(callback));
    if (tag != nullptr) {
      reader_ = async_call(context_.get(), request, &cq_->cq());

FYI: I think this is correct, but I had to read it like 3 times to convince myself there are no race conditions.

@coryan
Copy link
Contributor

coryan commented Jan 31, 2020

FWIW, the Windows failure is the flakiness I fixed in #143 . I restarted the build, but rebasing might help too.

Copy link
Contributor

@coryan coryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @mr-salty)


google/cloud/grpc_utils/internal/completion_queue_impl.h, line 105 at r1 (raw file):

Previously, mr-salty (Todd Derr) wrote…

I saw you added tests (thanks!) so I took what you did and added a new test, which uncovered a couple (or 3?) actual code bugs - PTAL

LGTM.

Copy link
Contributor Author

@mr-salty mr-salty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 5 of 6 files reviewed, all discussions resolved (waiting on @coryan)


google/cloud/grpc_utils/internal/async_read_stream_impl.h, line 161 at r3 (raw file):

Previously, coryan (Carlos O'Ryan) wrote…

FYI: I think this is correct, but I had to read it like 3 times to convince myself there are no race conditions.

Yeah, I had to convince myself a bit too :) I added a comment about it, thanks.

@mr-salty mr-salty merged commit 62b961b into googleapis:master Jan 31, 2020
@mr-salty mr-salty deleted the post-shutdown branch January 31, 2020 19:00
coryan pushed a commit to coryan/google-cloud-cpp that referenced this pull request Apr 24, 2020
googleapis/google-cloud-cpp-common#138)

* feat: gracefully fail adding to the `CompletionQueue` after `Shutdown`

The grpc `CompletionQueue` asserts if items are added to it after
`Shutdown()` is called. Make our `CompletionQueue` a little friendlier
by just failing those operations immediately.

Part of googleapis/google-cloud-cpp-common#129

* Add a test for making RPCs after `Shutdown()`, which uncovered a couple bugs

* Add a comment about the safety of leaving reader_ null in `Start`.
coryan pushed a commit to coryan/google-cloud-cpp that referenced this pull request Apr 24, 2020
googleapis/google-cloud-cpp-common#138)

* feat: gracefully fail adding to the `CompletionQueue` after `Shutdown`

The grpc `CompletionQueue` asserts if items are added to it after
`Shutdown()` is called. Make our `CompletionQueue` a little friendlier
by just failing those operations immediately.

Part of googleapis/google-cloud-cpp-common#129

* Add a test for making RPCs after `Shutdown()`, which uncovered a couple bugs

* Add a comment about the safety of leaving reader_ null in `Start`.
coryan pushed a commit to coryan/google-cloud-cpp that referenced this pull request Apr 24, 2020
googleapis/google-cloud-cpp-common#138)

* feat: gracefully fail adding to the `CompletionQueue` after `Shutdown`

The grpc `CompletionQueue` asserts if items are added to it after
`Shutdown()` is called. Make our `CompletionQueue` a little friendlier
by just failing those operations immediately.

Part of googleapis/google-cloud-cpp-common#129

* Add a test for making RPCs after `Shutdown()`, which uncovered a couple bugs

* Add a comment about the safety of leaving reader_ null in `Start`.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants