Skip to content

Commit ed88699

Browse files
committed
Exception in request handling if the server responds before the body is sent aio-libs#1761
1 parent 2b89766 commit ed88699

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Changes
99

1010
- Disable cleanup closed ssl transports by default.
1111

12+
- Exception in request handling if the server responds before the body is sent #1761
13+
1214

1315
2.0.4 (2017-03-27)
1416
------------------

aiohttp/web_protocol.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,8 @@ def start(self, message, payload, handler):
452452
now = loop.time()
453453
end_t = now + lingering_time
454454

455-
with suppress(asyncio.TimeoutError):
455+
with suppress(
456+
asyncio.TimeoutError, asyncio.CancelledError):
456457
while (not payload.is_eof() and now < end_t):
457458
timeout = min(end_t - now, lingering_time)
458459
with CeilTimeout(timeout, loop=loop):

tests/test_web_functional.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,25 @@ def handler(request):
102102
assert '' == txt
103103

104104

105+
@asyncio.coroutine
106+
def test_response_before_complete(loop, test_client):
107+
108+
@asyncio.coroutine
109+
def handler(request):
110+
return web.Response(body=b'OK')
111+
112+
app = web.Application()
113+
app.router.add_post('/', handler)
114+
client = yield from test_client(app)
115+
116+
data = b'0' * 1024 * 1024
117+
118+
resp = yield from client.post('/', data=data)
119+
assert 200 == resp.status
120+
text = yield from resp.text()
121+
assert 'OK' == text
122+
123+
105124
@asyncio.coroutine
106125
def test_post_form(loop, test_client):
107126

0 commit comments

Comments
 (0)