简体   繁体   English

(sanic)[错误]:写入响应之前连接已丢失

[英](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.

相关问题 websocket 连接丢失的 Sanic 警报 - Sanic alert on websocket connetion lost 重复错误:Sanic App中的NoneType - Repeated ERROR: NoneType in Sanic App Sanic(asyncio + uvloop webserver) - 返回自定义响应 - Sanic (asyncio + uvloop webserver) - Return a custom response 什么是错误代码意味着套接字连接丢失? - What are the error codes that mean the socket connection is lost? 鼠兔连接丢失错误:pika.exceptions.StreamLostError: Stream 连接丢失:ConnectionResetError(104, 'Connection reset by peer') - Pika connection lost Error: pika.exceptions.StreamLostError: Stream connection lost: ConnectionResetError(104, 'Connection reset by peer') 在 'localhost:3306' 与 MySQL 服务器的连接丢失,系统错误:连接不可用 - Lost connection to MySQL server at 'localhost:3306', system error: Connection not available 与 Sanic 保持始终运行的 ib_insync 连接 - Keeping an always-running ib_insync connection with Sanic Flask返回错误:断开与MySQL服务器的连接,系统错误:60 - Flask returns error: Lost connection to MySQL server, system error: 60 响应 python 模块的连接错误 - Connection error with response python module pandas:“与MySQL服务器的连接丢失”“系统错误:32管道断开” - pandas: “Lost connection to MySQL server” “system error: 32 Broken pipe”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM