<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Is it known bug?
</div><div>Can anyone propose a patch for prim_inet?</div><div><br></div><div>Thank you.</div>
<br><div><div>On 12.10.2012, at 1:06, Dmitry Belyaev wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Some days ago we found that we have thousands of leaked sockets in our project.</div><div><br></div><div>These sockets were ports with state like this:</div><div><div>[{name,"tcp_inet"},</div><div> {links,[]},</div><div> {connected,<0.54.0>},...]</div></div><div><br></div><div>We made investigation and found the cause of the leaks.</div><div><br></div><div>We have inets option {exit_on_close, false} to read statistics from the socket after it was closed by the peer. Process that controls the socket does not trap_exit and is linked with some another process.</div><div>At the end of connection controller calls gen_tcp:close/1 and sometimes the linked process dies at that the same moment. We found out that the gen_tcp:close/1 calls prim_inet:close/1, the first action of which is unlink from controlling process. So, when controller is unlinked from the port and is killed by the signal, port stays in the system because of exit_on_close feature.</div><div><br></div><div>I've made a module that sometimes may reveal the problem. <a href="https://gist.github.com/3875485">https://gist.github.com/3875485</a></div><div>On my system a half of dozen calls to close_bug:start(1000) do find such leaked ports. </div><div>I haven't found the right solution for the problem yet, so no patches at the moment.</div><div><br></div><div>Thank you for your attention.</div><div><br><div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>-- </div><div>Dmitry Belyaev</div></div></div></div></div></blockquote></div><br></body></html>