From 99575211eb02617e5fba58e8c1ba0959d53db6d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Mon, 17 Oct 2022 21:06:27 +0200 Subject: [PATCH] srht: Fix failing builds when triggered by git Without this fix builds, that were triggered by a git push, would cause the worker to crash: panic: GetJob: pq: unnamed prepared statement does not exist Those builds would stay "pending" forever. This is caused by Go's Postgres driver [1] [2] in combination with using PgBouncer in "Transaction pooling" mode. The recommended workaround is to set `binary_parameters=yes` in the connection string. If that is done in sourcehut's main config.ini file though, the python part of builds will fail: sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) invalid dsn: invalid connection option "binary_parameters" For that reason a separate config, which is used by the worker, is created and only differs in the connection-string. [1]: https://github.com/lib/pq/issues/889 [2]: https://github.com/lib/pq/pull/759 --- roles/srht/files/worker_override.conf | 3 +++ roles/srht/handlers/main.yml | 5 +++++ roles/srht/tasks/main.yml | 27 +++++++++++++++++++++++++++ roles/srht/templates/builds.ini.j2 | 4 ++++ 4 files changed, 39 insertions(+) create mode 100644 roles/srht/files/worker_override.conf diff --git a/roles/srht/files/worker_override.conf b/roles/srht/files/worker_override.conf new file mode 100644 index 0000000..5fb8dba --- /dev/null +++ b/roles/srht/files/worker_override.conf @@ -0,0 +1,3 @@ +[Service] +ExecStart= +ExecStart=/usr/bin/builds.sr.ht-worker --config /etc/sr.ht/worker.ini diff --git a/roles/srht/handlers/main.yml b/roles/srht/handlers/main.yml index 911832d..04b3816 100644 --- a/roles/srht/handlers/main.yml +++ b/roles/srht/handlers/main.yml @@ -5,6 +5,11 @@ state: restarted with_items: "{{ srht_services }}" +- name: Restart worker + ansible.builtin.systemd: + name: builds.sr.ht-worker + state: restarted + - name: restart nginx ansible.builtin.systemd: name: nginx diff --git a/roles/srht/tasks/main.yml b/roles/srht/tasks/main.yml index 40264b2..912a3c5 100644 --- a/roles/srht/tasks/main.yml +++ b/roles/srht/tasks/main.yml @@ -70,6 +70,33 @@ - git.sr.ht-webhooks.service - git.sr.ht-periodic.service +- name: Create systemd unit override path for worker + ansible.builtin.file: + path: /etc/systemd/system/builds.sr.ht-worker.service.d + state: directory + owner: root + group: root + mode: 0755 + +- name: Install worker systemd unit override file + ansible.builtin.copy: + src: worker_override.conf + dest: /etc/systemd/system/builds.sr.ht-worker.service.d/override.conf + owner: root + group: root + mode: 0644 + +- name: Configure worker + ansible.builtin.template: + src: config.ini.j2 + dest: /etc/sr.ht/worker.ini + owner: root + group: root + mode: 0644 + vars: + worker_config: true + notify: Restart worker + - name: Create db user community.general.postgresql_user: name: srht diff --git a/roles/srht/templates/builds.ini.j2 b/roles/srht/templates/builds.ini.j2 index 090b60a..f3a3a01 100644 --- a/roles/srht/templates/builds.ini.j2 +++ b/roles/srht/templates/builds.ini.j2 @@ -8,7 +8,11 @@ debug-host=0.0.0.0 debug-port=5002 # # Configures the SQLAlchemy connection string for the database. +{% if worker_config is defined and worker_config %} +connection-string=postgresql://srht:{{ srht_secrets['psql_password'] }}@localhost:6432/srht-builds?binary_parameters=yes +{% else %} connection-string=postgresql://srht:{{ srht_secrets['psql_password'] }}@localhost:6432/srht-builds +{% endif %} # # Set to "yes" to automatically run migrations on package upgrade. migrate-on-upgrade=yes -- 2.44.0