From 4cb76475167750ef03b747aded962db7f1702f88 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 9 Feb 2023 11:20:59 +0100 Subject: [PATCH] Add database pool configuration over `DB_POOL` to streaming API (#23470) Add connection timeout of 15s --- streaming/index.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/streaming/index.js b/streaming/index.js index e207411f2..1fbbdea3b 100644 --- a/streaming/index.js +++ b/streaming/index.js @@ -127,7 +127,6 @@ const startWorker = async (workerId) => { database: process.env.DB_NAME || 'mastodon_development', host: process.env.DB_HOST || pg.defaults.host, port: process.env.DB_PORT || pg.defaults.port, - max: 10, }, production: { @@ -136,20 +135,19 @@ const startWorker = async (workerId) => { database: process.env.DB_NAME || 'mastodon_production', host: process.env.DB_HOST || 'localhost', port: process.env.DB_PORT || 5432, - max: 10, }, }; - if (!!process.env.DB_SSLMODE && process.env.DB_SSLMODE !== 'disable') { - pgConfigs.development.ssl = true; - pgConfigs.production.ssl = true; - } - const app = express(); app.set('trust proxy', process.env.TRUSTED_PROXY_IP ? process.env.TRUSTED_PROXY_IP.split(/(?:\s*,\s*|\s+)/) : 'loopback,uniquelocal'); - const pgPool = new pg.Pool(Object.assign(pgConfigs[env], dbUrlToConfig(process.env.DATABASE_URL))); + const pgPool = new pg.Pool(Object.assign(pgConfigs[env], dbUrlToConfig(process.env.DATABASE_URL), { + max: process.env.DB_POOL || 10, + connectionTimeoutMillis: 15000, + ssl: !!process.env.DB_SSLMODE && process.env.DB_SSLMODE !== 'disable', + })); + const server = http.createServer(app); const redisNamespace = process.env.REDIS_NAMESPACE || null;