我在使用 tiangolo/uwsgi-nginx-flask 部署flask应用的时候,经常运行一会儿就出现502错误,重新启动容器后,就恢复。

且经常会出现数据更新后,刷新结果不一致。

docker作者的github中也有人遇到类似问题。https://github.com/tiangolo/uwsgi-nginx-flask-docker/issues/92

查询容器的日志可以看到upstream prematurely closed connection while reading response header from upstream

说是连接没有释放。现将解决方案记录一下:

http://flask.pocoo.org/docs/1.0/patterns/sqlalchemy/

在flask文档中有介绍使用一个装饰器来进行session释放。

from yourapplication.database import db_session

@app.teardown_appcontext
def shutdown_session(exception=None):
db_session.remove()

具体适用方法如下:

一:

from flask import Flask
from yourapplication.database import db_session
app = Flask(name)
@app.teardown_appcontext
def shutdown_session(exception=None):
  db_session.remove()

二:

from flask import Flask
from yourapplication.database import db_session
def create_app():
app = Flask(name)
return app
app = create_app() @app.teardown_appcontext
def shutdown_session(exception=None):
db_session.remove()
 

解决flask的502错误:upstream prematurely closed connection while reading response header from upstream的更多相关文章

  1. nginx error: upstream prematurely closed connection while reading response header from upstream

    本篇文章由:http://xinpure.com/nginx-error-upstream-prematurely-closed-connection-while-reading-response-h ...

  2. Nginx" upstream prematurely closed connection while reading response header from upstream"问题排查

    问题背景 我们这边是一个基于Nginx的API网关(以下标记为A),最近两天有调用方反馈,偶尔会出现502错误,我们从Nginx的error日志里看,就会发现有" upstream prem ...

  3. upstream prematurely closed connection while reading response header from upstream

    upstream prematurely closed connection while reading response header from upstream nginx配置uwsgi的时候  ...

  4. 修复Nginx 502错误:upstream sent too big header while reading response header from upstream

    原文出处:https://www.cnblogs.com/jpfss/p/10237463.html 便于以后参考我复制了过来! cookies的值超出了范围我是说 看看了一下日志 错误502 ups ...

  5. nginx log 错误502 upstream sent too big header while reading response header from upstream

    cookies的值超出了范围我是说 看看了一下日志 错误502 upstream sent too big header while reading response header from upst ...

  6. nginx 错误502 upstream sent too big header while reading response header from upstream

    查看nginx的错误日志,得到以下错误信息:upstream sent too big header while reading response header from upstream按字面意思理 ...

  7. 出现upstream sent too big header while reading response header from upstream错误

    一个POS系统,出现upstream sent too big header while reading response header from upstream错误. 1.反向代理端,可以放到se ...

  8. nginx recv() failed (104: Connection reset by peer) while reading response header from upstream解决方法

    首先说下 先看 按照ab 每秒请求的结果 看看 都有每秒能请求几个 如果并发量超出你请求的个数 会这样 所以一般图片和代码服务器最好分开 还有看看io瓶ding 和有没有延迟的PHP代码执行 0 先修 ...

  9. Nginx+PHP配置错误,日志:[error] 24324#0: *31 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream

    一.问题现象 1.安装nginx.php.php-fpm后,浏览器访问php报错,“File not found”: 二.问题排查 1.检查nginx.php-fpm服务是否正常启动,均正常启动: 2 ...

随机推荐

  1. CentOS 离线安装 MYSQL+APACHE+PHP

    一.MYSQL安装 下载MYSQL安装包:MySQL-client-XXX.rpm   MySQL-server-XXX.rpm   MySQL-devel-XXX.rpm 如有冲突,要先删除原来的M ...

  2. MSSQL 漏洞利用与提权

    1.SA口令的获取 webshell或源代码的获取 源代码泄露 嗅探(用CAIN等工具嗅探1433数据库端口) 口令暴力破解 2.常见SQL server 提权命令 查看数据库的版本(select @ ...

  3. 如何使用mongodb(建立原型,连接数据库)

    前两天看了一个朋友做的mongodb数据库,他是自己从某网络大学试听课学的,从可读性和模块区分方面做的比较差,所以写下此文,以作交流. 首先是创建一个modules文件夹,这里面用来存放mongodb ...

  4. freeswitch reloadxml 出错

    1.修改fs配置文件后,reloadxml控制台上报错误. 2,控制台日志显示 error near line 7301]:missing>] 查询 log 下的 freeswitch.xml. ...

  5. JS(JavaScript)的初了解7(更新中···)

    1.逻辑运算  ||   && ! 1||2   5&&4  !0 || 遇到第一个为true的数字就终止并返回 && 遇到第一个为false的值 就终 ...

  6. windows服务加定时器实现

    首先在项目中添加windows服务 然后双击“MainService.cs”,在上面点右键“打开代码” 以下是我的实例代码 partial class MainService : ServiceBas ...

  7. Python类元编程初探

    在<流畅的Python>一书中提到: Classes are first-class object in Python, so a function can be used to crea ...

  8. yii 邮箱封装

    <?php class Mailer { private static $obj; private static $config; public static function getMaile ...

  9. Git初识学习

    初始化一个Git仓库,使用git init命令. 添加文件到Git仓库,分两步: 使用命令git add <file>,注意,可反复多次使用,添加多个文件: 使用命令git commit ...

  10. Vue-admin工作整理(六):路由元信息

    路由源信息:每一个路由对象,可以配置一个meta字段,它里面可以存放一些我们定义的信息,比如说页面是否需要一个权限 to.meta && setTitle(to.meta.title) ...