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

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