-
Notifications
You must be signed in to change notification settings - Fork 1.6k
gRPC: add more unit tests for Stream
and Datastore
#1935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
ce6949c
lint
var-const f6f3f84
small fixes
var-const 282009c
Add grpc_connection_test
var-const 635c473
Missed test cases
var-const 59f070c
Review feedback
var-const 3139cb4
Forgotten files
var-const 7170b70
linter
var-const a0f061f
Remove unnecessary split
var-const 5bfc05b
quick fix
var-const 1d38fb1
Initial
var-const dd3d10c
Delete some of the more excessive tests
var-const 23070bb
Fix bug in WriteAndFinish
var-const 9dca0f9
Merge branch 'varconst/grpc-unit-tests-wrappers' into varconst/grpc-u…
var-const 928953a
compiles
var-const 29e726c
Merge branch 'master' into varconst/grpc-unit-tests-domain
var-const 40b6260
linter
var-const 7a86c73
Merge branch 'master' into varconst/grpc-unit-tests-domain
var-const 4c57926
Simple test fixes
var-const 7687464
Disable failing test, reenable fixed test
var-const 5c00ca6
style
var-const File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test currently fails, I'll fix before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this actually looks like a non-trivial issue.
The root of the problem is that there's an implicit dependency between
grpc::CompletionQueue
andgrpc::ByteBuffer
's lifetimes. The smallest repro is just:Details:
In gRPC, C core is initialized once and shut down once. All C++ classes that need the core to be initialized inherit from
GrpcLibraryCodegen
.GrpcLibraryCodegen
essentially makes C core reference-counted; each constructor increments, and each destructor decrements, the number of references to C core, and once the last reference is destroyed, the C core is shut down.In this case, destroying
Datastore
destroysgrpc::CompletionQueue
, which happens to be the last reference to C core, so the line 154 (datastore.reset()
) leads to global shutdown. The global shutdown, among other things, shuts downExecCtx
.When
EmptyCredentialsProvider::GetToken
is called, theTokenListener
(astd::function
) is passed by value, so at the end of the call the destructor ofTokenListener
is called, which leads to the destruction of a lambda created byDatastore
that contains agrpc::ByteBuffer
. When agrpc::ByteBuffer
is destroyed, it creates anExecCtx
, which fails because global shutdown has already been called onExecCtx
, leading to an assertion failure and a crash.(Note that the fact that
GetToken
takes its argument by value isn't really an issue here; if the argument were taken by reference, the problem would surface when the credentials provider is destroyed. The root of the problem seems that theByteBuffer
-containing lambda may outlive gRPC core).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wilhuff Re. the above:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Submitted an issue to gRPC repo: grpc/grpc#16875
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re (1): this could be a bug, but realistically I think it's one we'll have to work around. Possibly this means that we should not be using ByteBuffers for anything except directly sending into/out of gRPC calls such that the construction order you're describing never happens. However, it's also possible I'm misunderstanding, because it seems like we really shouldn't get into a state where we've destroyed the completion queue before the last byte buffer we might have submitted into it.
Re (2): I don't think the issue is that we care so much about auth outliving firestore as we want to handle races where Firestore may be asked to shutdown while an auth request is pending. We should not crash in this circumstance.
In our public API shutdown is asynchronous, so we could work around this by performing teardown in two passes: a first pass to quiesce the system, inhibiting new requests and waiting for any outstanding ones and then tearing things down.
Alternatively, for any request that might outlive the system add some way to disconnect it such that when it calls back it doesn't attempt any action on the already destroyed system.