protobuf-ts icon indicating copy to clipboard operation
protobuf-ts copied to clipboard

why does timout invalid?

Open WesleyBlq opened this issue 1 year ago • 2 comments

I am using grpc-web and have set the timeout options, but they do not seem to be working. I am unsure of the reason for this error. Can you help me identify the issue?

import { ArMockClient } from "@/infra/proto/ar_mock.client";
import { Empty } from "@/infra/proto/google/protobuf/empty";
import { GrpcWebFetchTransport } from "@protobuf-ts/grpcweb-transport";
import { logger } from "@/utils/logger";

class GRPCClient {
  constructor() {
    this.client = new ArMockClient(
      new GrpcWebFetchTransport({
        baseUrl: "http://192.168.10.210:8509",
        // timeout: 2000,
      })
    );
  }

  async GetArMockData() {
    logger.info("GetArMockData start");
    try {
      logger.info("GetArMockData start");
      const { response } = await this.client.getArMockData(Empty.create(), {
        timeout: 2000,
      });
      logger.info("GetArMockData end");
      return [...response.graphic.locations, ...response.graphic.polygons];
    } catch (e) {
      throw new Error("GetArMockData error");
    }
  }
}

export const grpcClient = new GRPCClient();

WesleyBlq avatar Mar 21 '23 10:03 WesleyBlq

I am facing a similar issue where configuring the timeout parameter in either GrpcWebFetchTransport or the service method itself proves ineffective. Furthermore, during my testing, I have observed that the timeout duration appears to be approximately 1.3 minutes (though this time estimate might be influenced by my current environment).

northsea4 avatar Aug 03 '23 09:08 northsea4

The timeout/deadline is simply sent as a request header to the server. There is no setTimeout being used client-side. The issue would be with the server not respecting the grpc-timeout request header (the server likely has its own timeout which is shorter than what you specified).

jcready avatar Aug 04 '23 19:08 jcready