fullstorydev / grpcurl

Like cURL, but for gRPC: Command-line tool for interacting with gRPC servers
MIT License
10.79k stars 503 forks source link

Can't make a request to localhost #186

Closed misiukevich-mifort closed 4 years ago

misiukevich-mifort commented 4 years ago

Hi, got a problem with sending request to my NestJs server with Transport.GRPC.

grpcurl -d '{"id": 1}' -plaintext -import-path nest-task/src/user -proto user.proto 127.0.0.1:3001 user.UserService/FindOne
Too many arguments.
Try 'grpcurl -help' for more details.
D:\>grpcurl -plaintext localhost:3001 list
Failed to dial target host "localhost:3001": context deadline exceeded

While this method is working corerctly

D:\>grpcurl -import-path nest-task/src/user -proto user.proto list
user.UserService
jhump commented 4 years ago

@misiukevich-mifort, grpcurl can make requests to local host just fine. That is almost exclusively how I use it, personally. Something else is going on.

For the first command, I don't quite understand why it failed. That command-line looks correct to me. What shell are you using? It is possible that the '{"id": 1}' was not correctly intepreted as a single argument and possibly provided to grpcurl as two arguments ('{"id": and 1}')?

Note that the last one works because it does not require a network connection: it is listing the services in the given proto sources.

I think you may need to do more troubleshooting for connectivity to localhost:3001. Is it possible a firewall was blocking traffic (so instead of a quick "connection refused" error, grpcurl saw it as a black hole, only detecting an error after timeout)? Or maybe there's something wrong with the configuration of the server such that it accepts the socket, but then never actually does anything with it (e.g. fails to process requests and handle HTTP/2 preamble)?

You might try using curl in HTTP/2 mode. It won't be easy to send a valid RPC (that's the point of grpcurl after all 😄), but you should at least be able to see if it can even connect. (If it can connect, you'll likely get back a "405 Method Not Allowed", "501 Unimplemented", or "400 Bad Request" error from the server, depending on what command-line flags you used).