matrix-synapse: keep generic worker endpoint order stable across runs

`matrix_synapse_workers_generic_worker_client_server_endpoints` and
`matrix_synapse_workers_generic_worker_federation_endpoints` dropped the
non-matching entries with `difference([none])`. ansible-core implements
`difference` as `list(set(a) - set(b))`, so the result follows Python's
per-process string hash seed and comes out in a different order on every
run.

The reverse-proxy companion renders these lists as nginx `location`
blocks, so its `conf.d/matrix-synapse-reverse-proxy-companion.conf`
changed, and the companion restarted, on every run, even with nothing
else to change.

`reject('none')` drops the same entries and keeps the order of
`matrix_synapse_workers_generic_worker_endpoints`. All these locations
point to the same upstream, so routing is unchanged.
This commit is contained in:
QEDeD
2026-10-19 09:11:18 +03:00
committed by Slavi Pantaleev
parent 0a7f0d0536
commit 56a51d8b8c
+5 -2
View File
@@ -80,14 +80,17 @@ matrix_synapse_workers_federation_reader_federation_endpoints:
# - some of these paths are auth-sensitive or deployment-sensitive, so we intentionally keep them out of the broad worker route model unless explicitly handled elsewhere
#
# Basically, we aim to cover most spec client APIs here. Skipping `/_synapse/client` is intentional and conservative.
matrix_synapse_workers_generic_worker_client_server_endpoints: "{{ matrix_synapse_workers_generic_worker_endpoints | default([]) | map('regex_search', '.*/_matrix/client.*') | list | difference([none]) }}"
# Here and in `matrix_synapse_workers_generic_worker_federation_endpoints` below, `reject('none')` is used instead of `difference([none])`.
# `difference` returns the items in an order that changes between Ansible runs, which would rewrite the reverse-proxy companion configuration
# (and restart its service) on every run.
matrix_synapse_workers_generic_worker_client_server_endpoints: "{{ matrix_synapse_workers_generic_worker_endpoints | default([]) | map('regex_search', '.*/_matrix/client.*') | reject('none') | list }}"
# A Synapse generic worker can handle both federation and client-server API endpoints.
# We wish to split these, as we normally serve federation separately and don't want them mixed up.
#
# This is some ugly Ansible/Jinja2 hack (seen here: https://stackoverflow.com/a/47831492),
# which takes a list of various strings and removes the ones NOT containing `/_matrix/federation` or `/_matrix/key` anywhere in them.
matrix_synapse_workers_generic_worker_federation_endpoints: "{{ matrix_synapse_workers_generic_worker_endpoints | default([]) | map('regex_search', matrix_synapse_workers_generic_worker_federation_endpoints_regex) | list | difference([none]) }}"
matrix_synapse_workers_generic_worker_federation_endpoints: "{{ matrix_synapse_workers_generic_worker_endpoints | default([]) | map('regex_search', matrix_synapse_workers_generic_worker_federation_endpoints_regex) | reject('none') | list }}"
# matrix_synapse_workers_generic_worker_federation_endpoints_regex contains the regex used in matrix_synapse_workers_generic_worker_federation_endpoints.
# It's intentionally put in a separate variable, to avoid tripping ansible-lint's jinja[spacing] rule.