0
votes

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

2

2 Answers

0
votes

Just turn off Debug Mode (You should when you're in production) and the error message will vanish.

0
votes

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