[英](sanic)[ERROR]: Connection lost before response written
I am using Sanic (Python) as a web server and facing an issue with some of the requests. 我将Sanic(Python)用作Web服务器,并且遇到了一些请求问题。 It's returning an error when we get quite a few simultaneous requests. 当我们同时收到多个请求时,它返回一个错误。 The error description is as below: 错误描述如下:
web_1 | 2017-10-03 09:24:49 - (network)[INFO][172.17.0.1:55372]: GET http://localhost:8000/api/order_items/123456 200 38
web_1 | 2017-10-03 09:24:50 - (network)[INFO][172.17.0.1:55382]: GET http://localhost:8000/api/order_items/123456 200 38
web_1 | 2017-10-03 09:24:55 - (network)[INFO][172.17.0.1:55392]: GET http://localhost:8000/api/order_items/123456 200 38
web_1 | 2017-10-03 09:24:56 - (sanic)[ERROR]: Connection lost before response 2343 written @ ('172.17.0.1', 55402)
web_1 | 2017-10-03 09:24:56 - (network)[INFO][172.17.0.1:55412]: GET http://localhost:8000/api/order_items/123456 200 38
web_1 | 2017-10-03 09:24:57 - (sanic)[ERROR]: Connection lost before response 2343 written @ ('172.17.0.1', 55424)
web_1 | 2017-10-03 09:24:57 - (network)[INFO][172.17.0.1:55430]: GET http://localhost:8000/api/order_items/123456 200 38
This is where Sanic is reporting this error: https://github.com/channelcat/sanic/blob/master/sanic/server.py#L333 Sanic在此报告此错误: https : //github.com/channelcat/sanic/blob/master/sanic/server.py#L333
So as per my understanding, HTTP connection is closing before Sanic can write to it which is fine but I should be able to override the behaviour and hide the error if I wish to which is something I need help with 因此,据我了解,在Sanic可以向其写入之前,HTTP连接已关闭,但是我应该能够重写此行为并隐藏错误,如果我希望对此有所帮助的话
只需关闭调试模式(在生产中就应该使用),错误消息就会消失。
The issue has been permanently fixed in Sanic but it hasn't been released yet. 该问题已在Sanic中永久修复,但尚未发布。 So here's a temporary solution until Sanic releases 0.6.1. 因此,这是一个临时解决方案,直到Sanic发布0.6.1。
class NoConnectionLostFilter(logging.Filter):
""" while issue not resolved https://github.com/channelcat/sanic/issues/959 """
def filter(record):
return not record.getMessage().startswith('Connection lost before response written')
logging.getLogger('root').addFilter(NoConnectionLostFilter)
Solution Credits: https://github.com/samael500 Github Issue link: https://github.com/channelcat/sanic/issues/959 解决方案积分: https : //github.com/samael500 Github问题链接: https : //github.com/channelcat/sanic/issues/959
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.