Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node Listen blocks indefinitely when assigned port is already taken #281

Open
lrahmani opened this issue Apr 29, 2020 · 0 comments
Open

Comments

@lrahmani
Copy link

Issue

When a node is created with noise.NewNode with a specific port number, if the port is already taken (* noise.Node) Listen will hugs indefinitely, even if the port is release and made available later.

Expected behavior

I expect (* noise.Node) Listen to immediately return an error.

How to reproduce it

This behavior is entirely reproducible using the chat example running on a ubuntu:18.4-based docker image.

  1. get the chat example go get -d -v github.com/perlin-network/noise/cmd/chat
  2. start a netcat server listening on port 10123 nc -l -p 10123
  3. run the chat example using the same port go run github.com/perlin-network/noise/cmd/chat -p 10123

How to bypass the issue (workaround)

One can test if the port is already taken before calling (* noise.Node) Listen by binding to it using net.ListenTCP. If the call is successful immediately close the listener and proceed to (* noise.Node) Listen. If the call is unsuccessful report the error produced by net.ListenTCP.

Here is a sample:

// ...
address := "127.0.0.1:10123"
tcp_addr, err := net.ResolveTCPAddr("tcp", address)
if err != nil {
  return err
}
listener, err := net.ListenTCP("tcp", tcp_addr)
if err != nil {
  return err
}
listener.Close()
err = node.Listen()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant