aio-libs / aio-libs/aiohttp

Closing connection on client half close, not allowing response.

未关闭
#3,659 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
enhancement
主要语言
Python
星标
16.5k
派生
2.4k
平均合并
17 小时 22 分钟
30 天内合并 PR
212

描述

## Long story short

A http client sends a request to aiohttp and immediately sends a fin, closing their side of the connection. Aiohttp calls the handler to generate the response, but closes the connection rather than sending it.

This is caused by [eol_received](https://github.com/aio-libs/aiohttp/blob/7345ffbc9666ad825927d785f3492b78fc7a2755/aiohttp/web_protocol.py#L264) returning None, as per [Protocol](https://docs.python.org/3.6/library/asyncio-protocol.html#asyncio.Protocol.eof_received). Having this function return True, fixes this issue.

I haven't been able to find any issues with this fix, even cleanly closing the connection after the response. But I am no expert on aiohttp.

## Expected behavior

aiohttp sends the response to the client and then closes the connection. The client.py prints the headers of the response.

## Actual behavior

aiohttp closes the connection without sending the response. client.py simply prints:

> Received b''

## Steps to reproduce

client.py ( it only prints the headers of the response on success, but sufficient for this) :
````
import socket

HOST = '127.0.0.1'
PORT = 8080
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((HOST, PORT))
s.sendall(b'GET / HTTP/0.9\r\n\r\n')
s.shutdown(socket.SHUT_WR)
data = s.recv(1025)
print('Received', repr(data))
````

server.py:
````
import asyncio

from aiohttp import web

async def handle(request):
print("handling request: {}".format(request))
asyncio.sleep(0.1) # ensure the fin shows up.
return web.Response(text="Hello")

app = web.Application()
app.add_routes([web.get('/', handle)])
web.run_app(app)
````
Run server.py first then client.py on the same machine.

## Your environment

aiohttp as a server
aiohttp version 3.5.4
Reproduced on Ubuntu and OSX. Python 3.6.5.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。