我在使用 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. AHOI2019游记

    day0 早上八点钟出发,下午一点左右到了(高速好堵啊) 下午试机,打了一发线段树,堆和其他一些东西,测试完没有问题就走了 惊奇发现旁边竟然是合肥市队的WC银牌hzy,%%% 晚上%了一发金牌爷yg就 ...

  2. php登录注册

    php 登录注册 注册代码:register.php <style type="text/css"> form{ width:300px; background-col ...

  3. jQuary学习の五のAJAX

    AJAX 是与服务器交换数据的技术,它在不重载全部页面的情况下,实现了对部分网页的更新. 一.jQuery load() 方法 jQuery load() 方法是简单但强大的 AJAX 方法. loa ...

  4. HTML与CSS的一些知识(四)

    续: line-height 用于设置一行文本行高,一般用于文本的垂直居中: display 用于设置元素的显示方式 float 浮动,让元素漂浮起来排列 浮动的影响: a.浮动后,行内元素可以支持宽 ...

  5. MpVue 致力打造H5与小程序的代码共用

    MpVue是什么 基于 Vue.js 的小程序开发框架 从底层支持 Vue.js 语法和构建工具体系. 使用vue开发小程序 修改了 Vue.js 的 runtime 和 compiler 实现,使其 ...

  6. Vue-admin工作整理(十一):Vuex-动态注册模块

    概述: 动态注册模块分为两种,一种是在根state下注册一个模块,一种是在模块下再自动注册一个模块 第一种:根state下动态注册模块: 思路:通过store来实现,this.$store来获取当前的 ...

  7. 小程序之 swiper高度根据图片高度变化

    今天做的是这个效果⬇️  swiper的高度根据图片的高度而改变 wxml:<swiper indicator-dots="{{indicatorDots}}" vertic ...

  8. lua相关的小知识

    lua的特性 1. 轻量级:一标准的C语言编写原发开放,编译后仅仅100K,占用内存小: 2. 扩展性:Lua提供了非常已于使用的扩展口和机制: 3. 支持面向过程编程和函数式编程 lua的数据类型 ...

  9. 使用Python编的猜数字小游戏

    import random secret = random.randint(1, 30) guess = 0 tries = 0 print("我叫丁丁,我有一个秘密数字!") p ...

  10. springboot访问数据库(MySql)

    1.使用JDBC访问数据库:JDBC是用于在Java语言编程中与数据库连接的API <dependency> <groupId>org.springframework.boot ...