How can I setup gRPC port?

Our service uses 4000 port for the backend and written in Rust.
Also, We use gRPC and use same port with 4000.
But I can not add gRPC port. it says it’s already used for HTTP.
How can I add gRPC port?

I saw that grpc api is being called but I am getting error in reponse.


That’s expected, you can’t start 2 TCP servers (HTTP & GRPC) listening on the same port.
You need to assign another port to your GRPC server. You will get another url/link to contact this port.

Thank you for your reply.
I have just deployed 2 services and tested gRPC.
As I told you, we use the same port for HTTP and gRPC and I confirmed it works well.
Thank you

How is that possible? Could you share the command on how you run your app and the logs associated? (Or even better, your code)

I don’t use any command for it.
The magic is our code. our backend is bound on 4000 port for incoming requests.
And it’s working as a hybrid service.
If the request is http then we redirect to http service.
if the request is grpc then we redirect to grpc service.
That’s all

However, there is a reference for the multiplex.

Thanks for the article I understand better now.

It is not possible in our case to do that because there is a reverse proxy in front of your service, and we need to configure the application protocol per port.

If you configure HTTP, the reverse proxy will terminate http2 request and transform them into an HTTP/1.1 request. So it will not work with GRPC as it is http2 only.

If you configure GRPC as protocol, the reverse proxy will not transform http2 into http1, but it will ensure that the traffic is actually grpc over http2 and will not forward it if it is regular http.

So you have 2 solutions, either

  • create 2 services so they can both listen on the port 4000, as you do
  • or make start your grpc server on a different port

however, grpc connection is being suspended after 10mins, how can I solve this issue? @Erebe @a_carrano


You can change the default idle timeout for grpc connection in the advance settings of your service.
If there is no activity in the connection after those timeouts, the reverse proxy is going to force close the connection.

I already changed to 3600 for both. it didn’t work.

@Erebe How can I change client_body_timeout?
I can not find an option

I think the issue is coming from your app, I have deployed this grpc service

and without any modification, I can stream data without any issue for more than 10min

.venv ❯ date; grpcurl -proto srv.proto  -d '{"greeting": "tutu"}' Greeter/stream > /dev/null ; date
Tue Mar 12 12:29:42 PM CET 2024

Those timeouts are going to trigger between 2 write/read call, so if you stream anything the connection will not be reset/closed.

Our services were running for 2 years without any issues in other devops platform.
We just used grpc_read_timeout and grpc_send_timeout 3600s
This is related with Nginx config for grpc.

Can you please check this?

On the most recent versions of ingress-nginx, changing these timeouts requires using the annotation. There are plans for future releases to allow using the Kubernetes annotations to define each timeout separately.

This what we do already,

Strange, I am sure our service don’t have any issue since it worked for 2 years.

@Erebe any update?
our services can not run long time due to grpc timeout.

You can declare your port as TCP instead of GRPC.

If you do that, you will not get any reverse proxy in front of your application, just plain/raw TCP directly exposed to internet.

Beware, that it will create a Load balancer on your cloud provider which cost money, so you should avoid using this setup for doing ephemeral environment,


This is current port

Please use GRPC if your port is a GRPC server, not HTTP.

as I mentioned before, we use same port for HTTP and GRPC