grpc / grpc-go

The Go language implementation of gRPC. HTTP/2 based RPC

Home Page:https://grpc.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

failed to listen: listen tcp :50051: bind: address already in use exit status 1

cifer-ai opened this issue · comments

What version of gRPC are you using?

1.62.1

What version of Go are you using (go version)?

go1.20 darwin/arm64

What operating system (Linux, Windows, …) and version?

macOS Ventura 13.1

What did you do?

I follow the instruction in https://grpc.io/docs/languages/go/quickstart/
I compile and execute the server using command
$ go run greeter_server/main.go

What did you expect to see?

I expect to see it complied and executed successfully.

What did you see instead?

I got this error:
failed to listen: listen tcp :50051: bind: address already in use
exit status 1

As I check my local port, there is nothing run on port 50051

I also try grpc-python and grpc-node and they show the similar error - address already in use.

In this case, please provide troubleshoot instruction to fix this error.

This looks like the local port is already in use. What is the command you are running to check?

First I use:
$ netstat
Then find for 50051 and it's not found.

Then I try:
$ lsof -i :50051
And it shows no result.

Then I try:
$ sudo lsof -i :50051
Now it shows that port is used, but after I try to kill this port with $ kill -9 $(lsof -ti:50051) it can't kill.

So I change to port 50052 in source code and now it works.

Thank you for your advice.

Ah, ok, makes sense. Glad you were able to figure it out!