From 9282d5e9fb7e6c1cf02789926e88da2c028b7e70 Mon Sep 17 00:00:00 2001 From: Ske Date: Wed, 14 Oct 2020 23:35:10 +0200 Subject: [PATCH] Add some more resiliency to DB errors --- PluralKit.Bot/Utils/MiscUtils.cs | 3 +++ PluralKit.Core/Database/Database.cs | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/PluralKit.Bot/Utils/MiscUtils.cs b/PluralKit.Bot/Utils/MiscUtils.cs index 96e7d7cb..4ce4b24c 100644 --- a/PluralKit.Bot/Utils/MiscUtils.cs +++ b/PluralKit.Bot/Utils/MiscUtils.cs @@ -52,6 +52,9 @@ namespace PluralKit.Bot // Ignore "Database is shutting down" error if (e is PostgresException pe && pe.SqlState == "57P03") return false; + // Ignore thread pool exhaustion errors + if (e is NpgsqlException npe && npe.Message.Contains("The connection pool has been exhausted")) return false; + // This may expanded at some point. return true; } diff --git a/PluralKit.Core/Database/Database.cs b/PluralKit.Core/Database/Database.cs index bfa66101..aea4f6fe 100644 --- a/PluralKit.Core/Database/Database.cs +++ b/PluralKit.Core/Database/Database.cs @@ -37,7 +37,10 @@ namespace PluralKit.Core _connectionString = new NpgsqlConnectionStringBuilder(_config.Database) { - Pooling = true, MaxPoolSize = 500, Enlist = false, NoResetOnClose = true + Pooling = true, MaxPoolSize = 500, Enlist = false, NoResetOnClose = true, + + // Lower timeout than default (15s -> 2s), should ideally fail-fast instead of hanging + Timeout = 2 }.ConnectionString; }