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/grpc-reflection] Issue with proto file dependencies only on second or next request #2631

Closed
gawsoftpl opened this issue Dec 14, 2023 · 0 comments

Comments

@gawsoftpl
Copy link
Contributor

gawsoftpl commented Dec 14, 2023

Resolution

I found issue and create pull request #2632 :

private getFileDependencies(file: IFileDescriptorProto): IFileDescriptorProto[] {
    const visited: Set<IFileDescriptorProto> = new Set();
    
    # Correct:
    const toVisit: IFileDescriptorProto[] = [...(this.fileDependencies.get(file) || [])];
    
    # was 
    # const toVisit: IFileDescriptorProto[] = this.fileDependencies.get(file) || [];
    
    while (toVisit.length > 0) {
      # Here loop get item and remove from array but if you 
      # dont spreed fileDendepencies, all depedencies will be removed from original array
      const current = toVisit.pop();

      if (!current || visited.has(current)) {
        continue;
      }

      visited.add(current);
      toVisit.push(...this.fileDependencies.get(current)?.filter((dep) => !visited.has(dep)) || []);
    }

    return Array.from(visited);
  }

Problem description

When I send first request to grpc reflection server everythings works fine, I can generate client.
But when I reset my client and send second request to grpc server I received error:

protobufjs@7.2.5/node_modules/protobufjs/src/namespace.js:410
        throw Error("no such Type or Enum '" + path + "' in " + this);
              ^
Error: no such Type or Enum 'google.protobuf.Timestamp' in Type .requestshistory.RequestCreateRequestItem

Reproduction steps

# requestshistory.proto
syntax = "proto3";

package requestshistory;

import "google/protobuf/timestamp.proto";

service RequestsHistoryService {
    rpc Create(RequestCreateRequest) returns (RequestsCreateResponse) {};
}


message RequestsCreateResponse{
    bool success = 1;
}

message RequestCreateRequestItem {
    string user_id = 1;
    string api_server_job_id=2;
    google.protobuf.Timestamp date=3;

}
# Grpc reflection client
import { GrpcReflection } from 'grpc-js-reflection-client';

const client = new GrpcReflection(host, ChannelCredentials.createInsecure());

// Get services without proto file for specific symbol or file name
const descriptor = await client.getDescriptorByFileName('requestshistory.proto');

// Create package services
const packageObject: any = descriptor.getPackageObject({
  keepCase: true,
  longs: String,
  enums: String,
  defaults: true,
  oneofs: true,
});
#Grpc reflection server

  const protoFiles = [
    __dirname + '/../proto/requestshistory.proto',
    __dirname + '/../proto/params.proto',
    __dirname + '/../proto/health.proto',
  ];

const server = new grpc.Server();

// reflection
const reflection = new ReflectionService(
  protoLoader.loadSync(protoFiles),
);
reflection.addToServer(server);

https://github.com/grpc/grpc-node/blob/d46360df74bbeaee95744b26b7b1e42fa7f10ac5/packages/grpc-reflection/src/implementations/reflection-v1.ts#L317C66-L317C66

Because issue is not appear only on first request propably error is with cache or some fileDependencies map:

private getFileDependencies(file: IFileDescriptorProto): IFileDescriptorProto[] {
    const visited: Set<IFileDescriptorProto> = new Set();

    **# Here on first request return file proto dependencies on second request return empty array**
    const toVisit: IFileDescriptorProto[] = this.fileDependencies.get(file) || [];
   

Environment

  • OS name, version and architecture: [e.g. Linux Ubuntu 23.10 amd64]
  • Node version [e.g. 20.10.0]
  • Node installation method [e.g. pnpm]
  • Package name and version [e.g. @grpc/grpc-js": "^1.9.13"]
@gawsoftpl gawsoftpl changed the title [@grpc/reflection] Issue with proto file dependencies only on second or next request [@grpc/grpc-reflection] Issue with proto file dependencies only on second or next request Dec 14, 2023
gawsoftpl added a commit to gawsoftpl/grpc-node that referenced this issue Dec 14, 2023
murgatroid99 added a commit that referenced this issue Dec 14, 2023
Fix issue #2631 [@grpc/grpc-reflection] Issue with proto file dependencies only on second or next request
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

No branches or pull requests

2 participants