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.
get the chat example go get -d -v github.com/perlin-network/noise/cmd/chat
start a netcat server listening on port 10123 nc -l -p 10123
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.
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.go get -d -v github.com/perlin-network/noise/cmd/chat
nc -l -p 10123
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 usingnet.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 bynet.ListenTCP
.Here is a sample: