uWSGI invalid request block size (max 4096)

问题描述:

项目使用Nginx + uWSGI + Python Flaks 提供Restful API服务,用户反馈同一个服务,部分请求会出现502 Bad Gateway Error,部分请求正常返回。

问题分析:

检查uWSGI 日志,发现有如下错误日志

uwsgi invalid request block size: 5922 (max 4096)...skip

可见是因为request header过大超过uWSGI默认设置导致请求被丢弃,需要更改配置。

官网解释 :uwsgi server is discarding request because of invalid request block size, By default, uWSGI allocates a very small buffer (4096 bytes) for the headers of each request. If receiving “invalid request block size” in logs, it could mean server need a  bigger buffer. Increase it (up to 65535) with the buffer-size option.

(If you receive ‘21573’ as the request block size in your logs, it could mean you are using the HTTP protocol to speak with an instance speaking the uwsgi protocol. Don’t do this.)

 为什么request header会变化?

 用户登录管理是通过Siteminder完成的,request header中的cookie会因为用户登录情况发生变化(Siteminder算法),部分会导致超过uWSGI header限制。

 

解决方法:

increase the buffer size in uWSGI settings.

buffer-size = 32768

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章