我在使用 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. STA 141A, Homework

    STA 141A, Homework 2Due April 30th 2019 (by 8 am) Name:Student ID:Section:Names of your study mates: ...

  2. gitlab备份

    #!/bin/bash backup_date=`date "+%Y_%m_%d"` delete_date=`date +%Y_%m_%d -d "7 days ago ...

  3. poj 1321 棋盘问题 (DFS深度优先搜索)

    Problem Description 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋 ...

  4. 不小心跳进安装Django-redis的坑

    为了写缓存这一块,我用pip install django-redis安装Django-redis. 它也把我的Django更新到最新了,我回头看下面的截图才发现的,把我的Django从1.8.2更新 ...

  5. Eclipse使用Maven,创建项目出现:Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resour

    使用maven创建简单的项目时候经常会遇到 Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resource ...

  6. Antd-Pro2.0版本如何修改代理,让Mock变为真实服务器接口

    Antd-pro2.0之前更改代理方式 更改.roadhogrc.mock.js export default { 'GET /api/*': 'http://localhost:8001/', 'P ...

  7. 压测过程中使用nmon对服务器资源的监控

    1.nmon工具的下载和安装: 官网:http://nmon.sourceforge.net/pmwiki.php 下载完成后进行解压,更改权限:chmod 777 2.查看linux系统的版本,再使 ...

  8. delphi提示“Undeclared identifier”TForm的缺少引用单元列表

    在interface uses  添加TForms;

  9. .NetCore WebApi 添加 Log4Net

    一 .配置 1.vs2019 创建一个.net core web程序,选择webapi 2.项目中添加一个配置文件:添加--新建项--XML文件,命名为log4net.config 我使用的是log4 ...

  10. OO-第一单元总结

    经过了前三次作业和两次实验的引导,我的编程思路在逐步从面向过程转向面向对象.也对面向对象有了初步的理解.虽然第一次实验由于自己没有及时完成导致没有提交过有些遗憾,但是第二次实验还是提交了几次的(虽然由 ...