Errno 24: Too many open files. But I am not opening files?
<p>I am using treq (<a href="https://github.com/twisted/treq" rel="nofollow">https://github.com/twisted/treq</a>) to query some other api from my web service. Today when I was doing stress testing of my own services, It shows an error</p>

<p><code>twisted.internet.error.DNSLookupError: DNS lookup failed: address 'api.abc.com' not found: [Errno 24] Too many open files.</code></p>

<p>But the problem is, my entire code I didn't open any file. I suspect it could be caused by the api I query goes down or blocked me (the api.abc.com) since my stress testing could be like a ddos to that end point. Still, in that case shouldn't that be something like refuse connection? I don't know why it will have that <code>Too many open files</code> error. Or is that caused by creating too much thread query?</p>

<p>"Files" include network sockets, which are a type of file on Unix-based systems.  The maximum number of open files is configurable with <code>ulimit -n</code></p>

<pre><code># Check current limit
$ ulimit -n
256

# Raise limit to 2048
$ ulimit -n 2048
</code></pre>

<p>It is not surprising to run out of file handles and have to raise the limit.  But if the limit is already high, you may be leaking file handles (not closing them quickly enough).  In garbage-collected languages like Python, the finalizer does not always close files fast enough, which is why you should be careful to use <code>with</code> blocks or other systems to close the files as soon as you are done with them.</p>

python asynchronous twisted