我在使用 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. 自制操作系统Antz(15)——实现启动界面

    AntzScript

  2. 除了使用new关键字,还有什么方法可以创建Java对象呢?

    今天来盘点一下除了使用 "new" 关键字创建对象,还有什么方法可以创建Java对象呢? 因为是创建对象,所以这里ioc容器不在范围内 我们先看一下常用的new关键字创建 Clas ...

  3. topcoder srm 610 div1

    problem1 link 计算每个格子向上的最大高度.然后每个格子同一行前面的格子以及当前格子作为选取的矩形的最后一行,计算面积并更新答案. problem2 link 对于两个数据$(x_{1}, ...

  4. vue3.0使用axios报错问题记录

    vue-cli3.0使用axios的时候出现错误,记录一下 报错信息: Uncaught TypeError: Cannot set property $axios of #<Vue> w ...

  5. 关于transactionscope 事务的脏数据

    在一个项目中,关于新客的检测,如果查询到积分记录就是老客,因为检测的之前先积分,因为使用的是事务,造成本地代码没提交前已经有该会员的积分记录,而到数据库中却查询不到记录.造成永远都是老客,解决的方法是 ...

  6. error LNK1169 找到一个或多个多重定义的符号的解决方法

    问题描述如下: 有 三个源文件,A.h.B.cpp.C.cpp. A.h是头文件,其中声明了三个变量a1.a2. a3. B.cpp是A.h中所声明的类的实现源代码,C.cpp是主程序文件.B.cpp ...

  7. Jenkins 改成中文语言显示

    到系统管理    插件管理中下载如下插件接口  Localization: Chinese (Simplified) 搜索的时候用ctrl+f 进行搜索,不要用Jenkins下面下的filter 只有 ...

  8. Halcon 标定与准确测量

  9. Python+turtle交互式绘图:可以用鼠标拖动的小海龟

    下面是我画海龟的过程: (1)打开python: 2.调用turtle库,先设置一些基础设置,与一个画龟的函数 from turtle import Screen,Turtle,mainloop cl ...

  10. robot_framework环境搭建

    1.python安装(必须是python2) 下载地址:https://www.python.org/ 2.setuptools安装 下载地址:https://pypi.python.org/pypi ...