Grpc-gateway: all SubConns are in TransientFailure

Created on 1 Dec 2017  Â·  11Comments  Â·  Source: grpc-ecosystem/grpc-gateway

Hi guys,

I tried to run this repo examples folder but didn't work as expected.

Step to reproduce:

  1. Install deps:
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
go get -u github.com/golang/protobuf/protoc-gen-go
  1. cd $GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/examples
  2. go build && ./examples or go run main.go
  3. In another terminal window:
➜ curl -X POST \
  http://localhost:8080/v1/example/echo_body \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d '{
        "id": "example"
}'
{"error":"all SubConns are in TransientFailure","code":14}%

I also got the same result with other endpoints POST http://localhost:8080/v1/example/echo/myid.

Any idea why I keep getting {"error":"all SubConns are in TransientFailure","code":14}%? How to make it work?

Thank you.

Most helpful comment

Nvm, I haven't started GRPC server

All 11 comments

Nvm, I haven't started GRPC server

Could you give some more information? How did you start it?

For anybody else getting this error - I have seen it on the client if the server panics and crashes. So, for a couple seconds, the server is down until kubernetes replaces the pod. It can be confusing to find the problem because you need the logs from the crashed container.

I have this issue on Mac OS X, any idea?

This is just indicative of the client not being able to connect to the server. Check your setup.

Ok so I did check my setup and, I found this link on internet that, even if I have others problems now, helped me to get rid of this error : https://github.com/mycodesmells/golang-examples/blob/master/grpc/cmd/server/main.go

The thing I just don't get with this example is that, the guy initialize the grpc server, half in main, half in a go routine, then he serv the http part of its server and, the only difference I see is that he initialize a part of it before the go routine instead of initializing everything inside of this go routine (I hope I am clear, english isn't my first language sorry)

@johanbrandhorst I'm getting the same error now. I did no code change with the setup. Could you please help?

@vaikzs I'm not sure what else I can add, this is an error returned from the gRPC client when it cannot connect to the server. Please ensure your gateway can connect to the gRPC backend.

@vaikzs Just as a side question, do you have any defer conn.close()? This might be where you issue comes from. Also, gRPC Gateway and gRPC server are two different instance (if I can tell so), make sure you're on different ports

@Emixam23 @johanbrandhorst Thanks for the responses. I guess my grpc server was not running for some reason. It seems to be fine now.

The README example just start Http server, not start rpc server
This can work

func run() error {
    ctx := context.Background()
    ctx, cancel := context.WithCancel(ctx)
    defer cancel()

    // Register gRPC server endpoint
    // Note: Make sure the gRPC server is running properly and accessible
    mux := runtime.NewServeMux()
    opts := []grpc.DialOption{grpc.WithInsecure()}
    err := gw.RegisterPushServiceHandlerFromEndpoint(ctx, mux, "localhost:8888", opts)
    if err != nil {
        return err
    }

    go func() {
        listener, err := net.Listen("tcp", conf.Config.Listen)
        if err != nil {
            log.Fatalln("listen failed:", err)
        }

        rpcServer := grpc.NewServer()

        gw.RegisterPushServiceServer(rpcServer, &service.PushServer{})
        if err := rpcServer.Serve(listener); err != nil {
            log.Fatalln("serve error:", err)
        }
    }()


    // Start HTTP server (and proxy calls to gRPC server endpoint)
    return http.ListenAndServe(":9999", mux)
}
Was this page helpful?
0 / 5 - 0 ratings