From 0e8ef8ef10e998b4cba9e73a05fb0b0a17403e13 Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Mon, 9 Feb 2026 17:36:59 +0200 Subject: [PATCH] Add retry logic for Synapse user registration on Connection refused When DB credentials change (derived from matrix_synapse_macaroon_secret_key), a running Synapse container may fail to connect to its database and stop serving requests. This causes register_new_matrix_user to fail with "Connection refused" when the matrix-user-creator role tries to register users. This extends the retry logic from 44b43a51b (which handled HMAC failures) to also handle Connection refused errors: restart Synapse (picking up the new config with updated credentials), wait for it to start, and retry. Caused by c21a80d232ffe7e924c539bebecb3d8e26187586 Co-Authored-By: Claude Opus 4.6 --- .../tasks/util/ensure_user_registered_synapse.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/roles/custom/matrix-user-creator/tasks/util/ensure_user_registered_synapse.yml b/roles/custom/matrix-user-creator/tasks/util/ensure_user_registered_synapse.yml index f00984a9d..63ad20057 100644 --- a/roles/custom/matrix-user-creator/tasks/util/ensure_user_registered_synapse.yml +++ b/roles/custom/matrix-user-creator/tasks/util/ensure_user_registered_synapse.yml @@ -31,10 +31,13 @@ matrix_synapse_register_user_result.rc != 0 and 'User ID already taken' not in matrix_synapse_register_user_result.stdout and 'HMAC incorrect' not in matrix_synapse_register_user_result.stdout + and 'Connection refused' not in matrix_synapse_register_user_result.stderr | default('') -- when: "'HMAC incorrect' in matrix_synapse_register_user_result.stdout | default('')" +- when: >- + 'HMAC incorrect' in matrix_synapse_register_user_result.stdout | default('') + or 'Connection refused' in matrix_synapse_register_user_result.stderr | default('') block: - - name: Restart Synapse due to HMAC failure (likely a registration_shared_secret change) + - name: Restart Synapse due to registration failure (likely a registration_shared_secret or DB credentials change) ansible.builtin.service: name: "matrix-synapse.service" state: restarted