Skip to content

Commit

Permalink
Make matrix-synapse-reverse-proxy-companion not report "502 Bad Gatew…
Browse files Browse the repository at this point in the history
…ay" when Synapse workers restart

Since nginx 1.27.3, we can make use of the `resolve` parameter for an `upstream`'s `server`,
to allow DNS resolution to happen continuously at runtime, not just once during startup.

Previously, this was not possible to do in an `upstream` block without
an nginx-plus subscription. Outside of an `upstream` block, we've used
and still use `set $backend ..` workarounds to get DNS resolution at
runtime, but now we can do it in `upstream` as well.
  • Loading branch information
spantaleev committed Mar 5, 2025
1 parent db993c5 commit 1c68fd0
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,18 @@
{% macro render_worker_upstream(name, workers, load_balance) %}
{% if workers | length > 0 %}
upstream {{ name }} {
{#
We need to use a zone so that the upstream is stored in shared memory,
otherwise we can't use `resolve` below, as reported by nginx:
> resolving names at run time requires upstream ".." in ... to be in shared memory
#}
zone {{ name }} 64k;

{{ load_balance }}
keepalive {{ ((workers | length) * 2) | string }};
resolver {{ matrix_synapse_reverse_proxy_companion_http_level_resolver }} valid=5s;
{% for worker in workers %}
server "{{ worker.name }}:{{ worker.port }}";
server "{{ worker.name }}:{{ worker.port }}" resolve;
{% endfor %}
}
{% endif %}
Expand Down

0 comments on commit 1c68fd0

Please sign in to comment.