我有一个Quart应用程序,我可以用它将响应回传给客户端。我使用asyncio.sleep来延迟响应完成,如果我将延迟设置为59秒,则一切正常。流完成时没有任何问题。如果我将时间增加到120秒,响应将显示为超时。也就是说,客户端接收到流的第一部分,但是大约60秒后,浏览器抛出一个错误,在Chrome中是: net::ERR_HTTP2_PROTOCOL_ERROR 200。火狐抛出了一个TypeError。
我正在使用超玉米和Nginx。
hypercorn config.py文件为:
Shutdown_timeout = 123.0
ssl_handshake_timeout = 123.0
startup_timeout = 123.0Nginx.conf中的相关设置:
location @proxy_to_app {
proxy_read_timout = 600s
}我不知道如何解决这个问题。
我找出了问题的根源。它与夸特、超玉米或Nginx没有任何关系。问题出在Cloudflare和http2上,它是由WriteTimeout引起的。请看这个答案:What's the net::ERR_HTTP2_PROTOCOL_ERROR about?
那么问题是,如何在Cloudlfare中改变这一点。
我没有将Quart配置为在http2中工作,这会有帮助吗?
发布于 2020-04-04 09:47:34
我找到的唯一解决方案是打破休眠状态,并向客户端发送临时数据,以保持连接活动。
async def async_generator():
content_arr = [
json.dumps({'first':'some data'}),
json.dumps({'alive':''}), #required to http2 connection alive
json.dumps({'final' : 'final data'})
]
for i,html in enumerate(content_arr):
print(i)
if i > 0:
await asyncio.sleep(59) #this delays sending the final data 118 seconds
yield html.encode()https://stackoverflow.com/questions/60781348
复制相似问题