Skip to content

Commit

Permalink
Handle socket error in FileResponse #1773
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Apr 8, 2017
1 parent fc1a04d commit f64e610
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Changes

- Handle RuntimeError from transport #1790

- Handle socket error in FileResponse #1773

- Dropped "%O" in access logger #1673


Expand Down
5 changes: 5 additions & 0 deletions aiohttp/web_fileresponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from . import hdrs
from .helpers import create_future
from .http_writer import PayloadWriter
from .log import server_logger
from .web_exceptions import (HTTPNotModified, HTTPOk, HTTPPartialContent,
HTTPRequestRangeNotSatisfiable)
from .web_response import StreamResponse
Expand Down Expand Up @@ -36,6 +37,7 @@ def _sendfile_cb(self, fut, out_fd, in_fd,
loop.remove_writer(out_fd)
if fut.cancelled():
return

try:
n = os.sendfile(out_fd, in_fd, offset, count)
if n == 0: # EOF reached
Expand Down Expand Up @@ -72,6 +74,9 @@ def sendfile(self, fobj, count):
fut = create_future(loop)
self._sendfile_cb(fut, out_fd, in_fd, offset, count, loop, False)
yield from fut
except:
server_logger.debug('Socket error')
self._transport.close()
finally:
out_socket.close()

Expand Down

0 comments on commit f64e610

Please sign in to comment.