Skip to content
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

GRPC interceptor support #8154

Closed
jayMedicalChain opened this issue Sep 27, 2021 · 7 comments
Closed

GRPC interceptor support #8154

jayMedicalChain opened this issue Sep 27, 2021 · 7 comments
Labels
needs triage This issue has not been looked into type: enhancement 🐺

Comments

@jayMedicalChain
Copy link

Feature Request

Problem

I have created multiple NestJs servers that communicate via GRPC. When deploying my services with docker i get an intermittent connection issues from GRPC ECONNRESET [{"message":"14 UNAVAILABLE: read ECONNRESET"}]. Judging by this issue posted on the @grpc/grpc-node it seems this is an issue with the library.

grpc/grpc-node#1907 (comment)

Solution i would like

Advice i got from posting on the node-grpc issue thread was to create an interceptor to retry requests, looking at the GrpcOptions within nest, nest does not allow for interceptors. A simple way allowing interceptors would be a nice feature to have.

information about interceptors can be found here

https://github.com/grpc/proposal/blob/master/L5-node-client-interceptors.md#examples

Teachability, Documentation, Adoption, Migration Strategy

Ideally you would be able to pass interceptors as options like so

export const grpcOptions: GrpcOptions = {
  transport: Transport.GRPC,
  options: {
     interceptors: [someInterceptor],
    url: `${env.SERVER_HOST}:${config.gateway.port}`,
    package: [
      config.gateway.users.v1.package,
      config.gateway.records.v1.package,
    ],
    protoPath: [
      config.gateway.users.v1.protoPath,
      config.gateway.records.v1.protoPath,
    ],
    loader: {
      includeDirs: [config.protoLoaderDir],
      arrays: true,
      enums: String,
    },
  },
};

What is the motivation / use case for changing the behavior?

Having these sort of intermittent issues that make API calls sporadically fail without a way to easily implement retries isn't great.

@jayMedicalChain jayMedicalChain added needs triage This issue has not been looked into type: enhancement 🐺 labels Sep 27, 2021
@nestjs nestjs locked and limited conversation to collaborators Sep 28, 2021
@nestjs nestjs unlocked this conversation Sep 28, 2021
@kamilmysliwiec
Copy link
Member

looking at the GrpcOptions within nest, nest does not allow for interceptors.

We might need to just update the interface given that the options object is actually passed down to the @grpc/grpc-node package.

@jayMedicalChain
Copy link
Author

jayMedicalChain commented Sep 28, 2021

I can confirm it is just a case of updating the interface, i have just tested and passing an an interceptor into the options via the interceptors property, like so, works fine.

const clientOptions: ClientsModuleOptions = [
  {
    name: "HP_USERS_PACKAGE",
    //@ts-ignore
    transport: Transport.GRPC,
    options: {
      channelOptions: {
        //@ts-ignore
        interceptors: [interceptor],
      },
      url: `${env.USERS_SERVICE}:${config.users.port}`,
      package: [config.users.users.v1.package],
      protoPath: [config.users.users.v1.protoPath],
      loader: {
        includeDirs: [config.protoLoaderDir],
        enums: String,
        arrays: true,
      },
    },
  },
];

@kamilmysliwiec
Copy link
Member

Would you like to create a PR to address this issue?

@Jaypov
Copy link

Jaypov commented Sep 28, 2021

sure thing, ill get it done either later today or tomorrow.

@kamilmysliwiec
Copy link
Member

Let's track this here #8231

@vietkute02
Copy link

This pull request expose interceptors option for grpc but it not pass this options to grpc-js client

@wdhxs
Copy link

wdhxs commented Aug 16, 2022

I can confirm it is just a case of updating the interface, i have just tested and passing an an interceptor into the options via the interceptors property, like so, works fine.

const clientOptions: ClientsModuleOptions = [
  {
    name: "HP_USERS_PACKAGE",
    //@ts-ignore
    transport: Transport.GRPC,
    options: {
      channelOptions: {
        //@ts-ignore
        interceptors: [interceptor],
      },
      url: `${env.USERS_SERVICE}:${config.users.port}`,
      package: [config.users.users.v1.package],
      protoPath: [config.users.users.v1.protoPath],
      loader: {
        includeDirs: [config.protoLoaderDir],
        enums: String,
        arrays: true,
      },
    },
  },
];

Hi~We have also encountered this problem recently. And we did it according to your method, but this interceptor did not be executed.
options: { channelOptions: { interceptors: [retryInterceptor], }, }
And the retryInterceptor is same as retry from https://github.com/grpc/proposal/blob/master/L5-node-client-interceptors.md#examples
Could you tell me why?Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage This issue has not been looked into type: enhancement 🐺
Projects
None yet
Development

No branches or pull requests

5 participants