Skip to content

Commit

Permalink
add optional nginx keepalive_timeout env to prevent race condition wi…
Browse files Browse the repository at this point in the history
…th gorouter

the current default of 30 causes the same inconsistent 502's as
https://community.pivotal.io/s/article/5004y00001buMQz1626802995951?language=en_US

and we need to set it to >90s so the gorouter is in charge of closing
the connections
https://docs.cloudfoundry.org/adminguide/routing-keepalive.html
  • Loading branch information
Sarel Joubert committed May 25, 2023
1 parent d51c18b commit 54bef2e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions buildpack/core/nginx.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def update_config():
samesite_cookie_workaround_enabled=samesite_cookie_workaround_enabled,
locations=_get_locations(),
default_headers=_get_http_headers(),
nginx_keepalive_timeout=_get_nginx_keepalive_timeout(),
nginx_port=str(util.get_nginx_port()),
runtime_port=str(util.get_runtime_port()),
admin_port=str(util.get_admin_port()),
Expand Down Expand Up @@ -136,6 +137,10 @@ def update_config():
_generate_password_file({"MxAdmin": security.get_m2ee_password()})


def _get_nginx_keepalive_timeout():
return os.environ.get("NGINX_KEEPALIVE_TIMEOUT", None)


def _get_proxy_buffer_size():
return os.environ.get("NGINX_PROXY_BUFFER_SIZE", None)

Expand Down
2 changes: 1 addition & 1 deletion etc/nginx/conf/nginx.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ http {
gzip_types text/plain text/css text/js text/xml text/javascript application/javascript application/x-javascript application/json application/xml application/xml+rss;

tcp_nopush on;
keepalive_timeout 30;
keepalive_timeout {% if nginx_keepalive_timeout %}{{ nginx_keepalive_timeout }}{% else %}30{% endif %};
absolute_redirect off;
server_tokens off;

Expand Down

0 comments on commit 54bef2e

Please sign in to comment.