Postgres: many requests at once no longer stop the site

Each Payload transaction holds a pool connection; code inside it that runs
without its req needs a second one (Payload's own forgotPassword, the mail
adapter's settings read and status write, payload.kv). With the default pool
of 10, ten form submissions or ten "forgot password" requests at once held
every connection and waited for good.

- connectionReserve (default on): at most pool size − reserve transactions
  open at once; a waiter older than a second may use all but the last
  connection. Building blocks in modules/database/transactions.ts.
- Form e-mails go out right after the submission's transaction commits, in
  the same request (forms.emailsInTransaction: true = the old way).
- recordIntegrationStatus merges identical writes and does not hold its
  caller while the pool is busy.
- SMTP time-outs: 10 s connect, 30 s greeting, 60 s silence (smtp.timeouts).

Tests on Postgres 17: 30 submissions, 30 forgot-password, and both against
an SMTP server that never answers, finish while a page answers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-26 00:33:07 +01:00
co-authored by Claude Opus 5.5
parent acfcf72c03
commit 32bb542e8e
25 changed files with 916 additions and 23 deletions
+12
View File
@@ -75,6 +75,18 @@ export type IaplOptions = {
*/
agency?: AgencyOption | false
/**
* Postgres: pool connections kept free of transactions. Payload holds a connection for the whole of a
* transaction, and code inside it that runs without the transaction's `req` (Payload's own "forgot
* password", an e-mail adapter reading its settings, a hook that forgot `req`) needs a second one: with
* the default pool of 10, ten such requests at once used to stop the whole site. With the reserve, at
* most `pool size − reserve` transactions are open at once and the next one waits for a place.
* Default: a fifth of the pool, at least 2 (1 in a pool of fewer than 4). A number sets it; `false`
* switches it off (as before 1.17.0). Other adapters: no effect. Building block: `reserveConnections`.
* docs/deployment.md "Postgres: the connection pool".
*/
connectionReserve?: false | number
/** Internationalization — locales, default locale, fallback behavior */
/**
* Consent log (proof of consent, GDPR Art. 7(1)): adds the `consent-records`