Getting Unimplemented desc = unknown service error gRPC
Asked Answered
S

7

14

In one of my services that happens to be my loadbalancer, I am getting the following error when calling the server method in one of my deployed services:

rpc error: code = Unimplemented desc = unknown service fooService.FooService

I have a few other services set up with gRPC and they work fine. It just seems to be this one and I am wondering if that is because it is the loadbalancer?

func GetResult(w http.ResponseWriter, r *http.Request) {

    conn, errOne := grpc.Dial("redis-gateway:10006", grpc.WithInsecure())       
    defer conn.Close()

    rClient := rs.NewRedisGatewayClient(conn)
    result , errTwo := rClient.GetData(context.Background(), &rs.KeyRequest{Key: "trump", Value: "trumpVal"}, grpc.WithInsecure())

    fmt.Fprintf(w, "print result: %s \n", result)   //prints nil
    fmt.Fprintf(w, "print error one: %v \n", errOne) // prints nil
    fmt.Fprintf(w, "print error two: %s \n", errTwo) // prints error

}

The error says there is no service called fooService.FooService which is true because the dns name for the service I am calling is called foo-service. However it is the exact same setup for my other services that use gRPC and work fine. Also my proto files are correctly configured so that is not an issue.

server I am calling:

 func main() {

    lis, err := net.Listen("tcp", ":10006")
    if err != nil {
        log.Fatalf("failed to listen: %v", err)
    }

    grpcServer := grpc.NewServer()
    newServer := &RedisGatewayServer{}
    rs.RegisterRedisGatewayServer(grpcServer, newServer)

    if err := grpcServer.Serve(lis); err != nil {
        log.Fatalf("failed to serve: %v", err)
    }

}

The function I am trying to access from client:

func (s *RedisGatewayServer) GetData(ctx context.Context, in *rs.KeyRequest)(*rs.KeyRequest, error) {

     return in, nil
}

My docker and yaml files are all correct also with the right naming and ports.

Sapro answered 11/5, 2018 at 9:30 Comment(7)
When it says “unknown service fooService.FooService,” what I think it is saying is that there is no grpc service Registered with that grpc path. Are you sure you registered a service with the exact same path?Wolfort
@Wolfort After I complied my .proto file it gave me a .pb.go file which specifies fooService.FooService as the service name. This is the same as the other .pb.go files I have for different services that are working fine. I implemented the code the exact same way also. The only thing different with this setup is the fact I have exposed a port on the service the grpc client code is running on. Is there a way I can manually add the service or check against the path? Not too sure how I would go about doing this.Sapro
unknown service fooServcie.FooService is that a typo?Araarab
@HanaAlaydrus yes sorry.Sapro
As @Wolfort mentioned, the error message indicates the service is not registered on the server. Double check that the service is registered on the server? Also, you mentioned load balancer, maybe also make sure the request is sent to the correct server?Sara
@Sara I think the issue might have been down to ImagePullPolicy not being declared in my deployment file. Meaning it was not using the most up to date image. I will need to test this when I have some time later though. Thanks!Sapro
Your question doesn't have much to do with "google-kubernetes-engine" or "google-cloud-platform" so I deleted those tags. Please do not add irrelevant tags to your questions.Lansing
V
11

I had this exact problem, and it was because of a very simple mistake: I had put the call to the service registration after the server start. The code looked like this:

err = s.Serve(listener)
if err != nil {
    log.Fatalf("[x] serve: %v", err)
}

primepb.RegisterPrimeServiceServer(s, &server{})

Obviously, the registration should have been called before the server was ran:

primepb.RegisterPrimeServiceServer(s, &server{})

err = s.Serve(listener)
if err != nil {
    log.Fatalf("[x] serve: %v", err)
}
Voluntary answered 26/3, 2022 at 21:30 Comment(0)
R
7

There are many scenarios in which this can happen. The underlying issue seems to be the same - the GRPC server is reachable but cannot service client requests.

The two scenarios I faced that are not documented in previous answers are:

1. Client and server are not running the same contract version

A breaking change introduced in the contract can cause this error.

In my case, the server was running the older version of the contract while the client was running the latest one.

A breaking change meant that the server could not resolve the service my client was asking for thus returning the unimplemented error.

2. The client is connecting to the wrong GRPC server

The client reached the incorrect server that doesn't implement the contract.

Consider this scenario if you're running multiple different GRPC services. You might be mistakingly dialing the wrong one.

Repentance answered 20/1, 2023 at 11:0 Comment(0)
C
1

thanks @dolan's for the comment, it solved the problem.

Basically we have to make sure, the method value should be same in both server and client (you can even copy the method name from the pb.go file generated from server side)

func (cc *ClientConn) Invoke(ctx context.Context, method string, args, reply interface{}, opts ...CallOption) error {

this invoke function will be there inside all the methods which you have implemented in gRPC service.

Cristen answered 4/7, 2020 at 7:52 Comment(0)
C
1

for me, my client was connecting to the wrong server port.

My server listens to localhost:50052

My client connects to localhost:50051

and hence I see this error.

Casanova answered 9/9, 2022 at 13:37 Comment(0)
C
0

I had the same problem - I was able to perform rpc call from Postman to the service whereas apigateway was able to connect to the service but on method call It gave error code 12 unknown service and the reason was in my proto files client was under package X whereas server was under package Y.

Quite silly but yeah making the package for both proto under apigateway and service solved my problem.

Crispi answered 18/1, 2023 at 19:26 Comment(0)
M
0

For me, it was that another process was hogging 50051 and my server didn't notice

Try moving both your client and server over to 50052.

Manifestative answered 22/12, 2023 at 8:27 Comment(0)
G
0

For me, i just package but forget to service:

  1. package yourPackageName

  2. service yourServiceName (i forget this step😵)

  3. call yourRPCName

Greisen answered 13/5 at 4:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.