Skip to content

binder: rework server SecurityPolicy future handling - #12954

Open
jdcormie wants to merge 4 commits into
grpc:masterfrom
jdcormie:jdcormie-binder-dedup-cancellation
Open

binder: rework server SecurityPolicy future handling#12954
jdcormie wants to merge 4 commits into
grpc:masterfrom
jdcormie:jdcormie-binder-dedup-cancellation

Conversation

@jdcormie

@jdcormie jdcormie commented Jul 29, 2026

Copy link
Copy Markdown
Member

Will not squash. Please consider each commit on its own.

@jdcormie
jdcormie force-pushed the jdcormie-binder-dedup-cancellation branch 2 times, most recently from c80e3d9 to b2fbe47 Compare July 30, 2026 00:21
@jdcormie jdcormie changed the title binder: fix SecurityPolicy handling on the server binder: rework server SecurityPolicy future handling Jul 30, 2026
@jdcormie
jdcormie force-pushed the jdcormie-binder-dedup-cancellation branch 3 times, most recently from 07e3a18 to 23be448 Compare July 30, 2026 08:29
@mateusazis
mateusazis self-requested a review July 30, 2026 16:31
RobolectricBinderSecurityTest has some tests already but some corners of
this class are hard to reach without flakiness at the Channel/Server
layer.
Include uncached methods in the deduping logic too.
@jdcormie
jdcormie force-pushed the jdcormie-binder-dedup-cancellation branch from 23be448 to 21328cf Compare August 4, 2026 01:14
Comment on lines +223 to +227
try {
Status authResult = awaitResult(authResultFuture);
fail("Expected authResultFuture cancellation but got " + authResult);
} catch (CancellationException expected) {
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe use JUnit's assertThrows instead?

fail("Expected authResultFuture cancellation but got " + authResult);
} catch (CancellationException expected) {
}
assertThat(authResultFuture.isCancelled()).isTrue();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Isn't this redundant with expecting a CancellationException?


fakePolicyChecker.takeNextAuthRequestOrDie().setException(new IllegalStateException("oops"));

ExecutionException exception = assertThrows(ExecutionException.class, () -> authResult1.get());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: use authResult1::get here as well for consistency? I think you did that in another test.

}

SettableFuture<Status> takeNextAuthRequestOrDie() throws InterruptedException {
SettableFuture<Status> item = statusesToSet.poll(10, java.util.concurrent.TimeUnit.SECONDS);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: import TimeUnit or static-import SECONDS.

directExecutor());
}

private static <T> T awaitNext(java.util.concurrent.BlockingQueue<T> queue) throws Exception {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: import BlockingQueue.

private static <T> T awaitNext(java.util.concurrent.BlockingQueue<T> queue) throws Exception {
T item = queue.poll(10, SECONDS);
if (item == null) {
throw new java.util.concurrent.TimeoutException("Queue timed out waiting for item");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: import TimeoutException.

return item;
}

private static <T> T awaitResult(java.util.concurrent.Future<T> future) throws Exception {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: import Future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

binder: Server fails to cancel SecurityPolicy.checkAuthorization() futures before termination

2 participants