Who uses the TCP port?

One of the gen_servers generators in my application is gen_tcp: listen (Port, [{active, true}]) . The first time I run the unit test, it returns {ok, Socket}, but the second time I run the same unit test, it returns {error, eaddrinuse}, but

lsof -i TCP 

returns nothing. In addition, when the same unit_test is run twice on another computer (WinXP), it works as expected (i.e. returns {ok, Socket) both times). So my gen_server obviously frees up the port, but Erlang somehow doesn't know this.

So, how can I understand who, according to Erlang, is using this address?

+6
source share
2 answers

This is due to the details of the TCP implementation on Unix systems - when a socket is opened for listening, it will remain unavailable for several minutes in the CLOSE_WAIT state after the listening process is completed.

From Lucas comment above: you can use the reuseaddr flag for gen_tcp: listen to avoid this

+9
source

If you are in windows, you can use the netstat utility to find out which process opened the port:

http://commandwindows.com/netstat.htm

netstat -a -b -v should do the trick

Linux netstat also supports showing users, but you need root to do this.

0
source

Source: https://habr.com/ru/post/901628/


All Articles