From 8cf851d9e62084982b570f2f466eae8a4bf65e66 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Thu, 19 Mar 2026 18:33:02 -0500 Subject: [PATCH] Add DB connection resilience settings (#89) ## Summary - Add `queue_target` (2s) and `queue_interval` (5s) to Repo config so DBConnection proactively replaces stale connections when queries slow down - Add TCP `keepalive: true` to prevent network intermediaries from silently dropping idle SSL connections Addresses the `ssl recv: closed` errors crashing `Oban.Met.Reporter` in production. ## Test plan - [x] Config-only change, compiles cleanly - [x] Pre-commit hooks pass Reviewed-on: https://git.mcintire.me/graham/towerops-web/pulls/89 --- config/runtime.exs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/config/runtime.exs b/config/runtime.exs index 54e9e61c..1fe02a66 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -307,9 +307,13 @@ if config_env() == :prod do ssl: ssl_config, url: database_url, pool_size: String.to_integer(System.get_env("POOL_SIZE") || "20"), - # For machines with several cores, consider starting multiple pools of `pool_size` - # pool_count: 4, - socket_options: maybe_ipv6 + # Detect stale connections faster: if a query takes longer than queue_target (2s) + # on average over queue_interval (5s), DBConnection will disconnect idle connections + # to cycle in fresh ones. Helps recover from "ssl recv: closed" errors. + queue_target: 2_000, + queue_interval: 5_000, + # TCP keepalive prevents proxies/firewalls from dropping idle connections + socket_options: maybe_ipv6 ++ [keepalive: true] config :towerops, Towerops.Vault, ciphers: [