From 56a51d8b8c86271d7ba233a92494ff049c10231c Mon Sep 17 00:00:00 2001 From: QEDeD Date: Sun, 18 Oct 2026 10:35:26 +0200 Subject: [PATCH] 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. --- roles/custom/matrix-synapse/vars/main.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/roles/custom/matrix-synapse/vars/main.yml b/roles/custom/matrix-synapse/vars/main.yml index a275c815e..0b21a60d0 100644 --- a/roles/custom/matrix-synapse/vars/main.yml +++ b/roles/custom/matrix-synapse/vars/main.yml @@ -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.