Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Too many open files #239
Comments
|
Where you using |
daleharvey
commented
Nov 5, 2011
|
nope, all requests were reasonably plain requests.get / requests.post, I am still seeing a few in there
all but 4/5 of them are of the format
|
|
I'm a bit baffled by this, to be honest. |
daleharvey
commented
Nov 26, 2011
|
Hah ill take another shot at reproducing it reliably, if I cant ill close |
|
I've seen this happening to me, but only when I'm using the async module w/ 200+ simultaneous connections. |
tamiel
commented
Dec 13, 2011
|
Hi, |
|
It may be problem of ulimit -n. Try with a higher value. |
tamiel
commented
Dec 22, 2011
|
"Too many open files" is the result of the bug caused by sockets staying in CLOSE_WAIT . |
|
@tamiel how do we fix this? |
tamiel
commented
Dec 22, 2011
|
I will do more tests asap and try to fix . |
|
I've looked into it, and seems to be a problem with all libraries using httplib.HTTPSConnection. |
tamiel
commented
Dec 22, 2011
|
Posted an example here : |
|
I just encountered a very similar error using an async pool with only HTTP connections - I'm still investigating but passing a pool size to async.map makes the error reproduce quickly. |
bevenky
commented
Jan 29, 2012
|
Any fixes to this? This makes Requests unusable with gevent.. |
|
It's all about the |
bevenky
commented
Jan 29, 2012
|
Is it a urllib3 issue? Having to close these by ourselves isnt a great idea i feel. |
|
It's more of a general issue. We can keep the conversation here. |
bevenky
commented
Jan 29, 2012
|
Ok just to give you a perspective, we are trying to move from httplib2 to requests, and we dont see this issue with httplib2. So its not a general issue for sure. |
|
By general i mean that it's a very serious issue that effects everyone involved. |
bevenky
commented
Jan 29, 2012
|
so how do we solve this? we really want to use requests + slumber moving forward |
|
I'd love to know the answer to that. |
kennethreitz
closed this
Jan 29, 2012
kennethreitz
reopened this
Jan 29, 2012
|
The leak appears to be due to the internal redirect handling, which causes new requests to be generated before the pending responses have been consumed. In testing acdha@730c0e2 has an under-satisfying but effective fix simply by forcing each response to be consumed before continuing. This required changes in two places which makes me want to refactor the interface slightly but I'm out of time to continue currently. |
added a commit
that referenced
this issue
Jan 29, 2012
|
#399 has a fix which works well in my async load generator (https://github.com/acdha/webtoolbox/blob/master/bin/http_bench.py) with thousands of requests and a low fd ulimit |
piotr-dobrogost
referenced this issue
Mar 29, 2012
Closed
requests leaves a hanging connection for each request #520
bborowin
commented
Apr 27, 2012
|
I have run into the same issue when using async -- kludged a workaround by chunking requests and deleting responses / calling gc.collect |
Cabalist
commented
Apr 30, 2012
|
I believe I was running into this today connecting to a licensed server that only allows 5 connections. Using async I could only GET 4 things before it paused for 60 seconds. Using the normal GET with consumption I could fetch about 150 things serially in under 40 seconds. Haven't made my kludge yet since I saw this issue. |
|
Just got this error while using ipython and got this message. This is just making each request one at a time, but I think I got something similar when using async.
Oddly, I think when using just the normal Python interpreter I get a "Max Retries Error" but I think that is another issue with me doing requests on all the same domain, but not sure. |
|
I ran into this on the first project I had where allow_redirects was True; it appears to be caused by the redirection chain leaking response objects which aren't released even with prefetch=True. This fixed it in my initial testing:
|
|
Hmmm.. |
|
@acdha setting:
before I make any requests still results in the same error, but I think this isn't an option for my implementation as all the requests I'm making will require a redirect =/ |
|
@dalanmiller How are you processing your responses? I was previously using for resp in requests.async.imap(reqs, size=8):
try:
print resp.status_code, resp.url
finally:
[i.raw.release_conn() for i in resp.history]
resp.raw.release_conn() |
|
I was just using a for loop through a url list and doing a request.get on each with my settings and such.
I tried using your paste and it works for about 50 requests in my 900 length list, until I start to get "max retries errors exceeded with url" for the rest. This is a pretty standard error though for hitting the same domain repeatedly though, no? |
dmishe
commented
Jun 7, 2012
|
Hey, i was crawling a huge list of urls, 35k, and got this same error on some of requests. I am getting urls in chunks of 10, like this:
Somewhere in 20k range i started getting error 24, then it was ok thru 30k and then again. Any more info you would be interested in to narrow it down? |
|
|
dmishe
commented
Jun 7, 2012
|
All right, thanks. Would be good to mention this in the docs. |
|
Kind of a noob when it comes to Pull Requests and writing documentation but I took a stab at it and sent it. Please comment or criticize :) |
dmishe
commented
Jun 9, 2012
|
Ok, this happends even without using async, with just requests.get, after 6K requests. |
|
I suspected that. |
lmillefiori
commented
Jul 3, 2012
|
For me the 'Too many open files' error occurred after downloading exactly 1k files. My solution was to disable keep-alive property, ever getting requests in chunks (@acdha thank you for the hint).
[1] chunking: http://stackoverflow.com/a/312464 |
|
Closing while deferring to urllib3 fix. |
kennethreitz
closed this
Jul 27, 2012
|
@kennethreitz What's the urllib3's issue number? |
silvexis
commented
Nov 28, 2012
|
Looks like this is the issue http://bugs.python.org/issue16298 |
|
@silvexis could very well be related to the urllib3 bug, now I'm just wishing someone had answered @piotr-dobrogost :P |
dmishe
referenced this issue
in kennethreitz/grequests
Mar 18, 2013
Closed
error(24, 'Too many open files') #9
barapa
commented
Aug 7, 2013
|
Is anyone else still encountering this issue? |
|
I haven't heard any reports of it. Are you? |
vladignatyev
commented
Aug 7, 2013
|
It's problem of the box config, not of the framework. Look at kernel configuration of your OS. In BSD it is called |
danfairs
commented
Aug 7, 2013
|
With the caveat that we're still running an older version of requests, we have the following, horrible, code in place to handle this:
(I think self._current_response is the requests' response object) |
|
Hmm, where is the chain of closing broken? We have a |
|
@Lukasa this was definitely fixed in urllib3 as I was part of the discussion. With an inclination towards being conservative in my estimate, I would say it's there since requests 1.2.x if not 1.1.x. |
|
Yeah, I did think this was fixed. Unless we see something on 1.2.3, I'm going to continue to assume this is fixed. |
|
I'm seeing a CLOSE_WAIT leak with 2.0.2, do you have unit tests to ensure there is no regression on the topic ? |
|
No, we don't. AFAIK urllib3 doesn't either. Can you reproduce your leak easily? |
|
We use request in our internal app since monday, and hit the 1024 maxfiles today.. 2 hours after reboot, we have 40 CLOSE_WAIT as told by lsof. So I think we'll be able to reproduce in a dev environment, yes. I'll keep you in touch |
|
@tardyp also, how did you install requests? I think all of the OS package maintainers strip out urllib3. If they don't keep that up-to-date and you're using an old version, that could be the cause instead. If you're using pip, then feel free to open a new issue to track this with instead of adding discussion onto this one. |
|
I installed with pip, but I use python 2.6, I've seen fix on python2.7 for Pierre On Fri, Nov 29, 2013 at 5:33 PM, Ian Cordasco notifications@github.comwrote:
|
|
@tardyp please open a new issue with as much detail as possible including whether the requests you're making have redirects and whether you're using gevent. Also, any details about the operating system and an example of how to reproduce it would be fantastic. |
This was referenced Dec 3, 2013
|
FYI shazow/urllib3#291 has been reverted due to bugs. |
added a commit
to sigmavirus24/urllib3
that referenced
this issue
Dec 4, 2013
polvoazul
commented
Nov 25, 2014
|
Should we re-open this? |
|
@polvoazul There's no way this is the same issue, which was originally reported in 2011, so I don't think reopening is correct. However, if you're running the current release of requests (2.4.3) and can reproduce the problem, opening a new issue would be correct. |
mygoda
commented
Jan 23, 2016
|
@Lukasa i need you help 。 i use eventlet + requests,that always create so many sock that can't identify protocol 。 my requests is 2.4.3, is eventlet + requests cause this problem? |
|
I'm sorry @mygoda, but it's impossible to know. If you aren't constraining the number of requests that can be outstanding at any one time then it's certainly possible, but that's an architectural problem outside the remit of requests. |
mygoda
commented
Jan 23, 2016
1a1a11a
commented
Mar 17, 2016
|
Having the same problem now, running 120 threads, cause 100000+ opened files, any solution right now? |
|
@mygoda you use awesome periods。 |
|
@1a1a11a What files do you have open? That'd be a useful first step to understanding this problem. |
|
@1a1a11a what version of requests are you using? What version of python? What operating system? Can we get any information? |
1a1a11a
commented
Mar 17, 2016
|
I am using request 2.9.1, python 3.4, ubuntu 14.04, basically I am writing a crawler using 30 threads with proxies to crawl some website. Currently I have adjusted the file limit per process to 655350, otherwise it will report error. |
miloharper
commented
Mar 17, 2017
|
I am still receiving the error "Failed to establish a new connection: [Errno 24] Too many open files" from requests.packages.urllib3.connection.VerifiedHTTPSConnection." I'm using Python 3.4, requests 2.11.1 and requests-futures 0.9.7. I appreciate requests-futures is a separate library, but it seems like the error is coming from requests. I'm attempting to make 180k asynchronous requests over SSL. I've divided those requests into segments of 1000, so I only move onto the next 1000 once all the future objects have been resolved. I'm running Ubuntu 16.04.2 and my default open files limit is 1024. It would be good to understand the underlying reason for this error. Does the requests library create an open file for each individual request? And if so, why? Is this a SSL certificate file? And does the requests library automatically close those open files when the future object is resolved? |
|
Requests opens many files. Some of those files are opened for certificates, but they are opened by OpenSSL and not by Requests, so those aren't maintained. Additionally, Requests will also open, if needed, the You will be best served by using a tool like |
dalanmiller
referenced this issue
Jul 17, 2014
Merged
If requests.async has been removed, the docs should point people to the right place. #665
tkaria
commented
Jul 11, 2017
|
I struggled with this issue as well and found that using |
nyurik
commented
Aug 29, 2017
|
I'm also frequently seeing this error when repeatedly calling |
|
What is |
nyurik
commented
Aug 29, 2017
|
A few hundred kb text |
|
Not a file object? |
nyurik
commented
Aug 29, 2017
|
No, I form a large query in memory. |
|
Are you running this code in multiple threads? |
nyurik
commented
Aug 29, 2017
|
No, single thread, posting to localhost |
|
It seems almost impossible for us to be leaking that many FDs then: we should be repeatedly using the same TCP connection or aggressively closing it. Want to check what your server is up to? |
iraykhel
commented
Sep 26, 2017
•
|
I am having this problem. Python 2.7, requests 2.18.4, urllib3 1.22. |
daleharvey commentedNov 5, 2011
I am building a basic load generator and started running into file descriptor limits, I havent seen any documentation pertaining to how to release resources, so either I am doing it wrong and the docs need updated, or requests is leaking file descriptors somewhere (without support for keepalive I am slightly confused at why any files would be left open at all)