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 12, 2017
1 parent ad3a287 commit 8a7832a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions aiohttp/web_fileresponse.py
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 8a7832a

Please sign in to comment.