<div dir="ltr">Hello,<br><br>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:<br>
<br>4> P.<br>#Port<0.100><br>5> is_port(P).<br>true<br>6> node(P).<br>nonode@nohost<br>7> erlang:port_info(P).<br>undefined<br>8> erlang:port_close(P).<br>** exception error: bad argument<br> in function port_close/1<br>
called as port_close(#Port<0.100>)<br>9> exit(P, kill).<br>true<br>10> lists:member(P, erlang:ports()).<br>true<br><br>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.<br>
<br>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.<br>
<br>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.<br><br>This has been reproduced on:<br>
<br>R12B-3, Ubuntu 6.06, i686<br>R11B-5, Ubuntu 7.04, x86_64<br><br>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. <br>
<br>Any help would be appreciated,<br><br>Malcolm<br><br></div>