node.jsgrpcgrpc-nodeprotobufjs

Getting `Error: 8 RESOURCE_EXHAUSTED: Received message larger than max (15217288 vs. 4194304)` in Node.js gRPC client


How to increase max message size for Node.js gRPC client?

We use grpc, grpc-tools and protobufjs npm-packages:

  const packageDefinitions = loader.loadSync(PROTO_PATH, { includeDirs: [__dirname], longs: String, arrays: true });
  const packageObject = grpc.loadPackageDefinition(packageDefinitions);
  const client = new packageObject.Service(serviceAddress, grpc.credentials.createInsecure());

Solution

  • For gRPC client and server we could specify gRPC params. For example, set the max messages size to 100 Mb:

    Client

      const client = new packageObject.Service(serviceAddress, grpc.credentials.createInsecure(), {
        "grpc.max_receive_message_length": 1024 * 1024 * 100,
        "grpc.max_send_message_length": 1024 * 1024 * 100
      });
    

    Server

      const server = new grpc.Server({
        "grpc.max_receive_message_length": 1024 * 1024 * 100,
        "grpc.max_send_message_length": 1024 * 1024 * 100
      });