unbit / uwsgi

uWSGI application server container
http://projects.unbit.it/uwsgi
Other
3.46k stars 692 forks source link

Bad file descriptor errors with cache2 and offload-threads #925

Open abathur opened 9 years ago

abathur commented 9 years ago

I'm not positive whether this is a bug, a misconfig on my part, or a hole in the documentation.

We've been trying to cache a json-returning endpoint in our application and already had offload-threads enabled for serving a few static assets. With no offload threads, the response comes back error-free from the cache, but with offload threads turned on, we get:

uwsgi_response_write_headers_do: Bad file descriptor [core/writer.c line 238] during GET

and the first line of the json response is missing. I didn't have time to really go digging, but after looking around in the code and related comments a bit, I wondered if this might be related to a warning about offload needing to be the last transform in the chain. We weren't able to find much documentation or other reports of the same issue, so I'll document our workaround and some related data which may help anyone seeing the same issue find it.

original route and cache directives:

route = ^/content_structure/$ cache:key=content,name=allcontent,content_type=application/json

workaround:

route = ^/content_structure/$ cache:key=content,name=allcontent,content_type=application/json,no_offload=true

Since the request still returns 200 on our development server, we didn't notice it until it started cropping up on one of our Heroku instances, where it was causing a cryptic H25 "HTTP restriction: oversized status line" error, which causes Heroku to return a 502 for the request. We initially suspected that cache or gzip were causing our problems

unbit commented 9 years ago

Hi, can you paste the whole config ? Thanks

abathur commented 9 years ago
[uwsgi]
http-socket = :5000
stats = :5050
master = true
threads = 1
enable-threads = true
workers = 4
wsgi-file = runserver.py
callable = app
memory-report = true
lazy = true
py-auto-reload = true
offload-threads=2
static-map = /static=test/static
static-gzip-all = true
http-auto-gzip = true

cache2 = name=allcontent,items=3,bitmap=1,blocks=30

route = ^/content_structure/$ cache:key=content,name=allcontent,content_type=application/json
route = ^/content_structure/$ cachestore:key=content,name=allcontent,expires=86400
yoobles commented 4 years ago

I recently ran into this issue and am fairly confident in saying that this is a uwsgi issue. This issue seems to be the only one discussing this issue but it seems like a valid problem.

I dont really know enough about uwsgi's code but the issue seems to probably be in this general area: https://github.com/unbit/uwsgi/blob/3149df02ed443131c54ea6afb29fcbb0ed4d1139/plugins/router_cache/router_cache.c#L197-L202