quarkiverse / quarkus-authzed-client

An extension for connecting to authzed instances from Quarkus applications
https://docs.authzed.com/reference/api
Apache License 2.0
5 stars 8 forks source link

PermissionsServiceStub gRPC Client call uses executor thread instead of event-loop #50

Closed senthilredhat closed 1 year ago

senthilredhat commented 1 year ago

I have a gRPC service calling another gRPC service. During response transformation, the thread switches from an event loop to an executor thread. After the gRPC call, the code tries to access Mutiny.session, which throws an error because the thread is an executor thread.

public Uni<Boolean> check(Relationship relationship) {
    if (!permissionCheckerEnabled)
        return Uni.createFrom().item(Boolean.TRUE);
    System.out.println("com.fga.SpiceDBRelationShipManager.check **" + Thread.currentThread().getName());
    return permissionsServiceStub.checkPermission(permissionRequestFromRelationship(relationship))
            .onItem().transform(checkPermissionResponse -> {
                System.out.println("com.fga.SpiceDBRelationShipManager.check.transform **" + Thread.currentThread().getName());
                return isPermitted(checkPermissionResponse);
            })
            .onFailure().recoverWithNull();
}

I validated that the grpc client call is processed in the event-loop thread using the quarkus annotation to generate the gRPC Client.

@GrpcClient("permissionService")
MutinyPermissionsServiceGrpc.MutinyPermissionsServiceStub permissionsServiceStub;

The client code on the quarkus extension needs updates to generate code similar to @GrpcClient annotation implementation to avoid using executor thread for the gRPC call.

iocanel commented 1 year ago

PR merge, this can be closed.