简体   繁体   中英

(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. 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

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

只需关闭调试模式(在生产中就应该使用),错误消息就会消失。

The issue has been permanently fixed in Sanic but it hasn't been released yet. So here's a temporary solution until Sanic releases 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM