<div class="gmail_quote">On Thu, Aug 6, 2009 at 6:22 PM, dave fowler <span dir="ltr">&lt;<a href="mailto:davefowler@gmail.com">davefowler@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I guys.  I&#39;m running a twisted web proxy and after a day or so of usage it stops working and start spitting out these errors.<br><br>2009/08/05 14:04 +0000 [__main__.ProxyFactory] Could not accept new connection (EMFILE)<br>



2009/08/05 14:04 +0000 [__main__.ProxyFactory] Could not accept new connection (EMFILE)<br>2009/08/05 14:04 +0000 [__main__.ProxyFactory] Could not accept new connection (EMFILE)<br>2009/08/05 14:04 +0000 [__main__.ProxyFactory] Could not accept new connection (EMFILE)<br>



2009/08/05 14:04 +0000 [__main__.ProxyFactory] Could not accept new connection (EMFILE)<br>2009/08/05 14:04 +0000 [__main__.ProxyFactory] Could not accept new connection (EMFILE)<br><br>Can anyone expand on what this error is or suggestions on fixing it or debugging further?  <br>

<br>What is the EMFILE?  <br></blockquote><div><br>It means you&#39;re out of file descriptors for your process.<br><br>See here for the root cause: &lt;<a href="http://linux.die.net/man/2/accept">http://linux.die.net/man/2/accept</a>&gt;,
specifically the part about EMFILE in the Errors section.  I&#39;m actually glad to see this error report - Twisted used to fail in a <i>much</i> worse way in this error condition (&lt;<a href="http://twistedmatrix.com/trac/ticket/662">http://twistedmatrix.com/trac/ticket/662</a>&gt;), this is the first proof I&#39;ve seen that our fix works in the wild :).<br>
<br>To increase your per-process file-descriptor limit, use &quot;ulimit -n&quot;.  Be aware that in order to increase this above 1024, you&#39;ll need to be root; I think there&#39;s a way to set it up to be bigger than that for non-root users but I don&#39;t know how.<br>
<br>In order to free up file descriptors, keep a list of your open connections and shut down some of them.  Sadly, your Factory object won&#39;t be notified of this problem, so you might have to hack something gross together (like a log observer that watches for the string &quot;(EMFILE)&quot;).  I just filed this ticket to provide a nice, clean notification: &lt;<a href="http://twistedmatrix.com/trac/ticket/3958">http://twistedmatrix.com/trac/ticket/3958</a>&gt;.  This may be a duplicate of something, but if so it should be closed with a link to what it&#39;s a duplicate of.<br>
<br>In some cases, connections won&#39;t shut down properly because there is still some buffered data and the other end is not available to acknowledge the connection&#39;s closure.  If this is the case, you can forcibly close the file descriptor (although this may cause some ugliness).  To get a good, supported way to destroy file descriptors in Twisted, see this ticket: &lt;<a href="http://twistedmatrix.com/trac/ticket/78">http://twistedmatrix.com/trac/ticket/78</a>&gt;.<br>
<br>Good luck!  Sorry Twisted has not handled this error in the best way for you, I hope you help us fix some of these bugs for the next guy :).<br><br></div></div>