[erlang-bugs] Unclosed ports causing memory leak

Malcolm Dowse malcolm@REDACTED
Tue Oct 14 13:22:12 CEST 2008


Hello,

We have been having some issues with Erlang ports not being closed properly.
Instead, the ports remain in a strange "half closed" state. In this state,
some aspects of the runtime system act as if the port exists
(erlang:ports/1) but others act as if it does not (erlang:port_info/1,
erlang:port_close/1). For example:

4> P.
#Port<0.100>
5> is_port(P).
true
6> node(P).
nonode@REDACTED
7> erlang:port_info(P).
undefined
8> erlang:port_close(P).
** exception error: bad argument
     in function  port_close/1
        called as port_close(#Port<0.100>)
9> exit(P, kill).
true
10> lists:member(P, erlang:ports()).
true

On our busiest servers one of these ports is generated every few minutes.
The result is that over months and months either the ERL_MAX_PORTS limit is
hit, or the ERTS process slowly balloons consuming all system memory. And
there appears to be no way to deallocate that memory without restarting
Erlang.

I've attached a short Erlang client & server which reproduces the problem.
The server, upon receiving a connection, immediately sends the client 65Kb.
When the client connects it immediately closes the socket before trying to
receive anything. The outcome, almost 100% of the time, is that the erlang
port on the server remains in this "half closed" state.

test_server:start(4444) starts the server on port 4444,
test_client:start(4444) starts the client (connecting to localhost), and
port_utils:show_broken_loop() prints port information to stdout.

This has been reproduced on:

R12B-3, Ubuntu 6.06, i686
R11B-5, Ubuntu 7.04, x86_64

Enabling/disabling SMP support or kernelpoll had no effect, but reducing the
65Kb down to 30Kb seemed to make the problem go away, at least in the test
case.

Any help would be appreciated,

Malcolm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20081014/90565cc0/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_server.erl
Type: application/octet-stream
Size: 632 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20081014/90565cc0/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_client.erl
Type: application/octet-stream
Size: 203 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20081014/90565cc0/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: port_utils.erl
Type: application/octet-stream
Size: 814 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20081014/90565cc0/attachment-0002.obj>


More information about the erlang-bugs mailing list