New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gunicorn+gevent/eventlet+flask+send_file, cStringIO? #1160

Closed
yijunjun opened this Issue Dec 9, 2015 · 8 comments

Comments

Projects
None yet
5 participants
@yijunjun

yijunjun commented Dec 9, 2015

in flask:
@app.route("/test")
def test():
import cStringIO
output = cStringIO.StringIO()
...
return send_file(output)

@benoitc

This comment has been minimized.

Show comment
Hide comment
@benoitc

benoitc Dec 10, 2015

Owner

@yijunjun what is the issue?

Owner

benoitc commented Dec 10, 2015

@yijunjun what is the issue?

@yijunjun

This comment has been minimized.

Show comment
Hide comment
@yijunjun

yijunjun Dec 11, 2015

Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 130, in handle
self.handle_request(listener, req, client, addr)
File "/usr/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 174, in handle_request
resp.write_file(respiter)
File "/usr/lib/python2.7/site-packages/gunicorn/http/wsgi.py", line 394, in write_file
if not self.sendfile(respiter):
File "/usr/lib/python2.7/site-packages/gunicorn/http/wsgi.py", line 357, in sendfile
fileno = respiter.filelike.fileno()
AttributeError: 'cStringIO.StringO' object has no attribute 'fileno'

yijunjun commented Dec 11, 2015

Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 130, in handle
self.handle_request(listener, req, client, addr)
File "/usr/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 174, in handle_request
resp.write_file(respiter)
File "/usr/lib/python2.7/site-packages/gunicorn/http/wsgi.py", line 394, in write_file
if not self.sendfile(respiter):
File "/usr/lib/python2.7/site-packages/gunicorn/http/wsgi.py", line 357, in sendfile
fileno = respiter.filelike.fileno()
AttributeError: 'cStringIO.StringO' object has no attribute 'fileno'

@benoitc

This comment has been minimized.

Show comment
Hide comment
@benoitc

benoitc Dec 11, 2015

Owner

@tilgovi ping

The issue comes from the removal of the fileobject testing:
18d2b92#diff-0b90f794c3e9742c45bf484505e3db8dL520

I am really not sure we shouldn't be strict there and only accept fileobjects providing a fileno method or attribute

@yijunjun in the mean time why do you want to use sendfile here? Why not simply returning an iterator (the StringIO would be enough). Gunicorn will stream it.

Owner

benoitc commented Dec 11, 2015

@tilgovi ping

The issue comes from the removal of the fileobject testing:
18d2b92#diff-0b90f794c3e9742c45bf484505e3db8dL520

I am really not sure we shouldn't be strict there and only accept fileobjects providing a fileno method or attribute

@yijunjun in the mean time why do you want to use sendfile here? Why not simply returning an iterator (the StringIO would be enough). Gunicorn will stream it.

@yijunjun

This comment has been minimized.

Show comment
Hide comment
@yijunjun

yijunjun Dec 11, 2015

I can solve this problem.I just want to report a problem.Thank you for your answer.

yijunjun commented Dec 11, 2015

I can solve this problem.I just want to report a problem.Thank you for your answer.

@tilgovi tilgovi self-assigned this Dec 11, 2015

@pudo

This comment has been minimized.

Show comment
Hide comment
@pudo

pudo Dec 16, 2015

Got the same issue. Wonder if it can't be caught more softly.

pudo commented Dec 16, 2015

Got the same issue. Wonder if it can't be caught more softly.

@volnt

This comment has been minimized.

Show comment
Hide comment
@volnt

volnt Dec 18, 2015

Got the same problem here too. How can this be avoided ?

volnt commented Dec 18, 2015

Got the same problem here too. How can this be avoided ?

@tilgovi

This comment has been minimized.

Show comment
Hide comment
@tilgovi

tilgovi Dec 18, 2015

Collaborator

We can catch the exception. I should be able to get to this over the weekend if no one else can. Closing any other issues on the milestone will help get this released faster.

Collaborator

tilgovi commented Dec 18, 2015

We can catch the exception. I should be able to get to this over the weekend if no one else can. Closing any other issues on the milestone will help get this released faster.

@benoitc

This comment has been minimized.

Show comment
Hide comment
@benoitc

benoitc Dec 28, 2015

Owner

@tilgovi sounds like a plan :)

Owner

benoitc commented Dec 28, 2015

@tilgovi sounds like a plan :)

@tilgovi tilgovi closed this in 98c9e3b Dec 28, 2015

fofanov pushed a commit to fofanov/gunicorn that referenced this issue Mar 16, 2018

Catch sendfile failure from no file descriptor
If the filelike response object has no `fileno` attribute, then skip
trying to use sendfile rather than failing with an error.

Close #1160
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment