2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

uWSGIが大きすぎるcookie送るとエラーを吐く件

Posted at

数時間調べたのでせっかくなのでメモ。

構成

Nginx 1.10.2 + uWSGI 2.0.14 のwebサーバ
python3.6 (Flask0.12)

現象

それなりの量のcookieを持ったリクエストを送信したら、Nginxのエラー画面が表示された

調査

  • アプリのログ→エラーは出ない。アプリのエラー画面がでないのでその前で事件は起きていると推測。
  • nginxのアクセスログ→該当リクエストでコード502返却
  • nginxのエラーログ
[error] 2622#0: *1237033 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: xxx.xxx.xxx.xxx, server: localhost, request: "GET /foo?bar=hoge HTTP/1.1", upstream: "uwsgi://path/to/uwsgi.sock", host: "hogehoge.com", referrer: "https://xxxxxx"

# 原因

Set the max size of a request (request-body excluded), this generally maps to the size of request headers. By default it is 4k. If you receive a bigger request (for example with big cookies or query string) you may need to increase it. It is a security measure too, so adapt to your app needs instead of maxing it out.

つまり、bodyを除いたリクエストの受信可能な上限があって、デフォルト4K。
問題のリクエストではcookieにそこそこのjsonを格納して送信していたのだが、これが引っかかった模様。
大きいクエリストリングも注意らしい。

対策

uWSGIの設定をiniに記載していたため、

uwsgi.ini
buffer-size=10240

を追記してuWSGI再起動してOK。
とりあえず10Kを設定したが、もっと大量のデータが想定される場合はそれ相応のサイズを設定してもいいのかも。

参考

https://github.com/unbit/uwsgi/issues/682
https://stackoverflow.com/questions/22697584/nginx-uwsgi-104-connection-reset-by-peer-while-reading-response-header-from-u/22792850#22792850
http://uwsgi-docs.readthedocs.io/en/latest/Options.html#buffer-size

プレミアムフライデー何それ美味しいの

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?