(sanic)[错误]:在写入响应之前连接丢失
(sanic)[ERROR]: Connection lost before response written
我正在使用 Sanic (Python) 作为网络服务器,并且遇到了一些请求的问题。当我们同时收到很多请求时,它会返回一个错误。错误描述如下:
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
这是 Sanic 报告此错误的地方:
https://github.com/channelcat/sanic/blob/master/sanic/server.py#L333
所以根据我的理解,HTTP 连接在 Sanic 可以写入之前关闭,这很好,但如果我愿意,我应该能够覆盖该行为并隐藏错误,这是我需要帮助的事情
只需关闭调试模式(在生产环境中应该关闭),错误消息就会消失。
该问题已在 Sanic 中永久修复,但尚未发布。所以这是一个临时解决方案,直到 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)
解决方案学分:https://github.com/samael500
Github 问题 link:https://github.com/channelcat/sanic/issues/959
我正在使用 Sanic (Python) 作为网络服务器,并且遇到了一些请求的问题。当我们同时收到很多请求时,它会返回一个错误。错误描述如下:
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
这是 Sanic 报告此错误的地方: https://github.com/channelcat/sanic/blob/master/sanic/server.py#L333
所以根据我的理解,HTTP 连接在 Sanic 可以写入之前关闭,这很好,但如果我愿意,我应该能够覆盖该行为并隐藏错误,这是我需要帮助的事情
只需关闭调试模式(在生产环境中应该关闭),错误消息就会消失。
该问题已在 Sanic 中永久修复,但尚未发布。所以这是一个临时解决方案,直到 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)
解决方案学分:https://github.com/samael500 Github 问题 link:https://github.com/channelcat/sanic/issues/959