[erlang-questions] Port is included in erlang:ports(), but erlang:port_info(Port) returnes 'undefined'

skyman cloudzen@REDACTED
Tue Mar 19 16:36:42 CET 2013


Hi everyone,
I encounter a problem:
While server socket is sending packets, client socket closes, then I find the socket's send_pend( inet:getstat(Socket, [send_pend]) ) is always > 0, that is some data isn't sent out. After closing the port, I find the port is still included in erlang:ports(), but erlang:port_info(Port) returnes 'undefined'. I guess that because the port's send queue is not empty, the erts set the port's status to be ERTS_PORT_SFLG_CLOSING, so the results between erlang:ports() and erlang:port_info() are inconsistent. The code:


void erts_do_exit_port(Port *p, Eterm from, Eterm reason)
{
   ...
   if ((reason != am_kill) && !is_port_ioq_empty(p)) {
       erts_port_status_bandor_set(p,
                                        ~ERTS_PORT_SFLG_EXITING, /* must turn it off */
                                        ERTS_PORT_SFLG_CLOSING);
      flush_port(p);
   }
   ...
}


The problem can only exist with TCP option: {delay_send, true}. When set {delay_send, false}, the problem disappears.


In addition, on this occasion erlang:halt() cannot terminate the node, have to use erlang:halt(Status, [{flush,false}]).


Can anyone help me? Thanks in advance!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130319/18a52106/attachment.htm>


More information about the erlang-questions mailing list