From def7ef1ff6badb92d490e28ad4e580f853983f65 Mon Sep 17 00:00:00 2001 From: bramhanandlingala Date: Wed, 8 Jul 2026 16:23:59 +0530 Subject: [PATCH] Delay pgbouncer preStop shutdown to avoid dropped connections during rolling restart --- .../helm_tests/airflow_aux/test_container_lifecycle.py | 2 +- chart/values.schema.json | 2 +- chart/values.yaml | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/chart/tests/helm_tests/airflow_aux/test_container_lifecycle.py b/chart/tests/helm_tests/airflow_aux/test_container_lifecycle.py index a1c2c63f6137a..ab8ee9cc65a29 100644 --- a/chart/tests/helm_tests/airflow_aux/test_container_lifecycle.py +++ b/chart/tests/helm_tests/airflow_aux/test_container_lifecycle.py @@ -55,7 +55,7 @@ def test_check_default_setting(self): assert jmespath.search("spec.template.spec.containers[0].lifecycle", doc) is None pgbouncer_default_value = { - "exec": {"command": ["/bin/sh", "-c", "killall -INT pgbouncer && sleep 120"]} + "exec": {"command": ["/bin/sh", "-c", "sleep 10 && killall -INT pgbouncer && sleep 20"]} } assert pgbouncer_default_value == jmespath.search( "spec.template.spec.containers[0].lifecycle.preStop", docs[-1] diff --git a/chart/values.schema.json b/chart/values.schema.json index 7eb865997c7b0..7027d8accc1e5 100644 --- a/chart/values.schema.json +++ b/chart/values.schema.json @@ -7827,7 +7827,7 @@ "command": [ "/bin/sh", "-c", - "killall -INT pgbouncer && sleep 120" + "sleep 10 && killall -INT pgbouncer && sleep 20" ] } } diff --git a/chart/values.yaml b/chart/values.yaml index 890f9976d970c..8a8bae8c37c14 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -2859,8 +2859,10 @@ pgbouncer: containerLifecycleHooks: preStop: exec: - # Allow existing queries clients to complete within 120 seconds - command: ["/bin/sh", "-c", "killall -INT pgbouncer && sleep 120"] + # Sleep first so the pod is marked Terminating and removed from + # Service endpoints before pgbouncer stops accepting connections, + # then gracefully drain existing queries. + command: ["/bin/sh", "-c", "sleep 10 && killall -INT pgbouncer && sleep 20"] metricsExporterSidecar: resources: {}