Skip to content

Conversation

@voidzcy
Copy link
Contributor

@voidzcy voidzcy commented May 7, 2021

Control plane RPCs are independent of application RPCs, they can stand for completely different lifetime. So the context for making application RPCs should not be propagated to control plane RPCs.

@voidzcy voidzcy requested a review from ejona86 May 7, 2021 22:15
…t of any application RPC that created it. It should not be impacted by the lifetime of Context used to make application RPCs.
@voidzcy voidzcy force-pushed the bugfix/use_standalone_context_for_control_plane_rpcs branch from 3048421 to d26c02a Compare May 7, 2021 22:15
@ejona86
Copy link
Member

ejona86 commented May 7, 2021

Will you do a follow-up with a test?

@voidzcy
Copy link
Contributor Author

voidzcy commented May 7, 2021

Will you do a follow-up with a test?

Well, there isn't a good way to test this unless we have something end to end. I was able to reproduce the issue with XdsClient's test, by attaching a CancellableContext before making the xDS RPC and then close the context to let the watcher receives the error as we saw. But after the change for using a standalone context, that kind of test code looks very weird, more of lying to ourselves.

@ejona86
Copy link
Member

ejona86 commented May 7, 2021

We could have a test in a ClientXdsClientTest potentially. Watch a resource, then cancel the Context, then watch another resource and see if it succeeds. You'd arrange it to make sure the backoff doesn't trigger during the test.

But since we have a manual test verification, if that unit test is too much effort/takes too long then it is better to merge as-is.

@voidzcy
Copy link
Contributor Author

voidzcy commented May 7, 2021

Watch a resource, then cancel the Context, then watch another resource and see if it succeeds.

That's what I did for reproducing the issue, something like:

CancellableContext cancellableContext = Context.current().withCancellation();
Context baseContext = cancellableContext.attach();

try {
   // watch to some resource
   cancellableContext.close();
   // verify watcher receives the error
} finally {
  cancellableContext.detach(baseContext);
}

It's simple as that. But after the fix, such a test to verify things working correctly looks very strange, isn't it? As just from the code, it's quite unintuitive/non-obvious to relate the context here to that in application RPCs. It's weak and tests very little. So I'd lean toward not put such a test.

@ejona86
Copy link
Member

ejona86 commented May 7, 2021

But after the fix, such a test to verify things working correctly looks very strange, isn't it?

Nah, that looks fine. It guarantees that the Context is handled properly by the implementation. As far as non-obvious, put a comment on it or some such.

@voidzcy
Copy link
Contributor Author

voidzcy commented May 7, 2021

But after the fix, such a test to verify things working correctly looks very strange, isn't it?

Nah, that looks fine. It guarantees that the Context is handled properly by the implementation. As far as non-obvious, put a comment on it or some such.

Well, still. Now we are injecting a Context to the XdsClient, and that's just the ROOT in test. So if we test that, we are basically testing the test code :). I'd say this is a more like a static behavior from the scope of XdsClient, so just testing such would not be useful.

@ejona86
Copy link
Member

ejona86 commented May 7, 2021

So if we test that, we are basically testing the test code :).

No, we are testing that "the xds client uses context a and not context b" sort of thing. If xds client ignores the Context.ROOT argument, that would trigger a test failure, so it seems fair.

@voidzcy
Copy link
Contributor Author

voidzcy commented May 7, 2021

No, we are testing that "the xds client uses context a and not context b" sort of thing. If xds client ignores the Context.ROOT argument, that would trigger a test failure, so it seems fair.

Okay, added a simple test case for it.

@voidzcy voidzcy merged commit 7b09056 into grpc:master May 8, 2021
voidzcy added a commit to voidzcy/grpc-java that referenced this pull request May 10, 2021
Control plane RPCs are independent of application RPCs, they can stand for completely different lifetime. So the context for making application RPCs should not be propagated to control plane RPCs. This change makes control plane RPCs use the ROOT Context.
voidzcy added a commit that referenced this pull request May 10, 2021
…kport) (#8153) (#8157)

Control plane RPCs are independent of application RPCs, they can stand for completely different lifetime. So the context for making application RPCs should not be propagated to control plane RPCs. This change makes control plane RPCs use the ROOT Context.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants