Skip to content

Commit

Permalink
Catch sendfile failure from no file descriptor
Browse files Browse the repository at this point in the history
If the filelike response object has no `fileno` attribute, then skip
trying to use sendfile rather than failing with an error.

Close #1160
  • Loading branch information
tilgovi committed Dec 28, 2015
1 parent 960d5ef commit 98c9e3b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gunicorn/http/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,10 @@ def sendfile(self, respiter):

try:
fileno = respiter.filelike.fileno()
except AttributeError:
return False

try:
offset = os.lseek(fileno, 0, os.SEEK_CUR)
if self.response_length is None:
filesize = os.fstat(fileno).st_size
Expand Down

1 comment on commit 98c9e3b

@wbolster
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong. See #1174.

Please sign in to comment.