-
Notifications
You must be signed in to change notification settings - Fork 3k
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
TCP Connection Ports Leaks #9529
Comments
Hello! There is an option called When shutting down the Erlang VM you can either make it flush or not flush all open connections, how does |
Hello @garazdawi,
I will check that on our application and come back to you.
|
We are using cowboy |
You can get the value by doing |
Indeed. All connections in our applications are using
It could then explain why the VM is not stopped, because all the connections are still active, totally outside of the scope of the VM (shutdown procedure), but available in background until the connections are explicitly closed by the node (killing the tcp connections with
The another "incarnation" of the connection seems a problem, what does it really mean? When we are closing the socket, it can still be re-activated by the client? Furthermore, does this "incarnation" behavior can also be seen when using a timeout? |
When you don't use |
Describe the bug
When shutting down an Erlang node, if an active TCP connection is still established with a remote peer, the connection is not closed, even if the process linked/connected to the port was killed. It can lead to a very slow shutdown if the connection used by the remote peer has a huge latency or a small bandwidth.
To Reproduce
We discovered this bug using
cowboy
but it can also be reproduced withinets:httpd
:cowboy
orinets:httpd
)curl
using--limit-rate ${value}
where${value}
is close to0
.[ erlang:port_info(X) || X <- erlang:ports() ]
sudo ss -ntip
on GNU/Linux ordoas fstat -u ${user}
on OpenBSD.ss -K
on GNU/LinuxA full example as escript is present at the end of this bug report.
Expected behavior
When stopping
cowboy
,inets:httpd
or any service using TCP, the active connection should be properly closed and/or killed.Affected versions
This bug has been reproduced on:
cowboy
/inets
cowboy
/inets
cowboy
/inets
inets
Additional context
It looks like the bug is from
erts/emulator/drivers/common/inet_drv.c
and was introduced in ebbd26e. Not sure though, but during the investigation, it seems this part of the code does not receive the instruction to close the connection.The bug can easily be reprouced with the following code:
Here some example of leaked ports. The port is not linked, and the process is not existing (dead):
The connections can be seen using these commands:
Those ports cannot be closed using
erlang:port_close/1
. Here another debugging session from an erlang shell whereinets
has been stopped:EDIT1: added ports/process info and corrected few typos
EDIT2: added more information regarding leaked ports.
The text was updated successfully, but these errors were encountered: