Re:dash でそこそこ大きいデータを Excel ダウンロードしようとするとエラーが発生することがある。
nginx のエラーログに以下のログが出力されていれば、Re:dash コンソールから叩いている API 側でタイムアウトが発生している。
2018/05/08 03:16:40 [error] 31782#0: *10976469 upstream prematurely closed connection while reading response header from upstream, ...
環境
redash.0.10.1.b1834 (公式 AMI で構築した Ubuntu 環境)
変更手順
Re:dash の API は Python の flask で実装されていて、gunicorn で起動している模様。
なので、gunicorn の timeout オプションを渡してあげれば OK。
/opt/redash/supervisord/supervisord.conf
を編集して、タイムアウト値を設定する
ここでは 300 秒で設定。
[program:redash_server]
command=/opt/redash/current/bin/run gunicorn -b 127.0.0.1:5000 --name redash -w 4 --max-requests 1000 --timeout 300 redash.wsgi:app
supervisord を reload する
supervisord.conf を編集したら reload が必要となる。
redash_server の worker が再起動される。
$ sudo supervisorctl reload redash_server
ps コマンドを叩くと、オプションが適用されていることが確認できる。
$ ps aux | grep /usr/local/bin/gunicorn
redash 1437 0.0 0.9 248120 70584 ? S May09 0:02 /usr/bin/python /usr/local/bin/gunicorn -b 127.0.0.1:5000 --name redash -w 4 --max-requests 1000 --timeout 300 redash.wsgi:app
redash 2985 0.0 0.9 248232 70680 ? S May09 0:00 /usr/bin/python /usr/local/bin/gunicorn -b 127.0.0.1:5000 --name redash -w 4 --max-requests 1000 --timeout 300 redash.wsgi:app
redash 3223 0.0 0.9 248372 70924 ? S May09 0:01 /usr/bin/python /usr/local/bin/gunicorn -b 127.0.0.1:5000 --name redash -w 4 --max-requests 1000 --timeout 300 redash.wsgi:app
ubuntu 8441 0.0 0.0 10432 672 pts/0 S+ 01:10 0:00 grep --color=auto /usr/local/bin/gunicorn
redash 28836 0.0 0.9 248444 70900 ? S May09 0:05 /usr/bin/python /usr/local/bin/gunicorn -b 127.0.0.1:5000 --name redash -w 4 --max-requests 1000 --timeout 300 redash.wsgi:app
redash 32199 0.0 0.1 56780 13876 ? S May08 0:16 /usr/bin/python /usr/local/bin/gunicorn -b 127.0.0.1:5000 --name redash -w 4 --max-requests 1000 --timeout 300 redash.wsgi:app
nginx の リバースプロキシのタイムアウト値を設定する
前段に nginx がいるので、こちらのタイムアウト値も設定しておく。
ちなみに設定ファイルは /etc/nginx/sites-available/redash
にあった。
proxy_connect_timeout 300s;
proxy_read_timeout 300s;
nginx をリロードして反映させれば OK。
$ service nginx reload