问题描述
我在heroku上托管了一个flask-socketio应用程序,其中包含以下Procfile:
I have a flask-socketio app hosted on heroku with the following Procfile :
web: gunicorn --worker-class eventlet hello:app
自从我切换到socketio以来,该应用程序的表现就一直不一致.早些时候,该应用程序将运行一段时间,然后POST请求将开始超时.
Ever since I switched to socketio, the app has been behaving inconsistenly. Earlier the app would run for a while and then POST requests would start timing out.
从昨天晚上开始,我不断收到错误消息
Since yesterday night, I keep getting the error
sock=backend at=error code=H18 desc="Server Request Interrupted" method=GET path="/static/js/third-party/browser.js" host=deard.herokuapp.com request_id=725da6af-aa29-4293-a411-2c89977f1d4d fwd="216.165.95.0" dyno=web.1 connect=1ms service=36ms status=503 bytes=13811
我阅读了heroku错误代码描述,内容为:在后端返回HTTP响应之前,关闭了属于您应用的Web进程的后端套接字."
I read the heroku error code description which says "The backend socket, belonging to your app’s web process was closed before the backend returned an HTTP response."
但是我不知道为什么会这样.
But I have no clue why this would be happening.
关于我应该寻找的任何线索,将帮助我调试此问题.
Any clue as to what I should be looking out for, will help me debug this.
我可以共享代码,但是它的长度为300行,并且由于我不知道错误的出处,所以不确定是否会有所帮助.
I could share the code but its 300 lines long and since I don't know where the error is originating from, I am not sure if it would be helpful.
推荐答案
这对我有用:
from waitress import serve
# app.run(host='0.0.0.0', port=port) # <---- REMOVE THIS
# serve your flask app with waitress, instead of running it directly.
serve(app, host='0.0.0.0', port=port) # <---- ADD THIS
这篇关于Heroku sock = Flask SocketIO应用程序的后端服务器请求中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!