requests icon indicating copy to clipboard operation
requests copied to clipboard

Too many open files

Open daleharvey opened this issue 15 years ago • 81 comments

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)

daleharvey avatar Nov 05 '11 12:11 daleharvey

Where you using requests.async?

kennethreitz avatar Nov 05 '11 14:11 kennethreitz

nope, all requests were reasonably plain requests.get / requests.post, I am still seeing a few in there

$ lsof | grep localhost | wc -l
110

all but 4/5 of them are of the format

Python    82117 daleharvey  123u    IPv4 0xffffff800da304e0       0t0      TCP localhost:61488->localhost:http (CLOSE_WAIT)

daleharvey avatar Nov 05 '11 14:11 daleharvey

I'm a bit baffled by this, to be honest.

kennethreitz avatar Nov 26 '11 15:11 kennethreitz

Hah ill take another shot at reproducing it reliably, if I cant ill close

daleharvey avatar Nov 26 '11 16:11 daleharvey

I've seen this happening to me, but only when I'm using the async module w/ 200+ simultaneous connections.

kennethreitz avatar Nov 26 '11 16:11 kennethreitz

Hi, I got exactly the same problem using requests and monkey patching with gevent : some connections staying in CLOSE_WAIT . Maybe a problem with gevent so .

michaelricordeau avatar Dec 13 '11 17:12 michaelricordeau

It may be problem of ulimit -n. Try with a higher value.

juanriaza avatar Dec 22 '11 00:12 juanriaza

"Too many open files" is the result of the bug caused by sockets staying in CLOSE_WAIT . So ulimit won't fix just make a workaround .

michaelricordeau avatar Dec 22 '11 21:12 michaelricordeau

@tamiel how do we fix this?

kennethreitz avatar Dec 22 '11 21:12 kennethreitz

I will do more tests asap and try to fix .

michaelricordeau avatar Dec 22 '11 22:12 michaelricordeau

I've looked into it, and seems to be a problem with all libraries using httplib.HTTPSConnection.

kennethreitz avatar Dec 22 '11 22:12 kennethreitz

Posted an example here :

https://gist.github.com/1512329

michaelricordeau avatar Dec 22 '11 23:12 michaelricordeau

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.

acdha avatar Jan 17 '12 20:01 acdha

Any fixes to this? This makes Requests unusable with gevent..

bevenky avatar Jan 29 '12 18:01 bevenky

It's all about the CLOSE_WAITs. Just have to close them. I'm not sure why they're still open though.

kennethreitz avatar Jan 29 '12 18:01 kennethreitz

Is it a urllib3 issue? Having to close these by ourselves isnt a great idea i feel.

bevenky avatar Jan 29 '12 19:01 bevenky

It's more of a general issue. We can keep the conversation here.

kennethreitz avatar Jan 29 '12 19:01 kennethreitz

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.

bevenky avatar Jan 29 '12 21:01 bevenky

By general i mean that it's a very serious issue that effects everyone involved.

kennethreitz avatar Jan 29 '12 21:01 kennethreitz

so how do we solve this? we really want to use requests + slumber moving forward

bevenky avatar Jan 29 '12 21:01 bevenky