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:
co-authored by
Claude Opus 5.5
parent
acfcf72c03
commit
32bb542e8e
@@ -20,8 +20,19 @@ export type PanelSmtpAdapterArgs = {
|
||||
*/
|
||||
fallbackFromAddress?: string
|
||||
fallbackFromName?: string
|
||||
/**
|
||||
* How long a send waits for the SMTP server, in milliseconds: `connectionMs` to connect (default 10 000),
|
||||
* `greetingMs` for its greeting (default 30 000), `socketMs` of silence during the dialogue (default 60 000).
|
||||
* A send that runs inside a database transaction (Payload's "forgot password") holds a connection that long.
|
||||
*/
|
||||
timeouts?: SmtpTimeouts
|
||||
}
|
||||
|
||||
export type SmtpTimeouts = { connectionMs?: number; greetingMs?: number; socketMs?: number }
|
||||
|
||||
/** nodemailer's own defaults are 2 minutes to connect and 10 minutes of silence. */
|
||||
export const SMTP_TIMEOUT_DEFAULTS: Required<SmtpTimeouts> = { connectionMs: 10_000, greetingMs: 30_000, socketMs: 60_000 }
|
||||
|
||||
/**
|
||||
* Payload email adapter backed by the SMTP settings in the SiteIntegrations
|
||||
* global.
|
||||
@@ -83,11 +94,15 @@ export const panelSmtpAdapter =
|
||||
|
||||
const { default: nodemailer } = await import('nodemailer')
|
||||
|
||||
const timeouts = { ...SMTP_TIMEOUT_DEFAULTS, ...args.timeouts }
|
||||
const transporter = nodemailer.createTransport({
|
||||
auth: { pass, user },
|
||||
connectionTimeout: timeouts.connectionMs,
|
||||
greetingTimeout: timeouts.greetingMs,
|
||||
host,
|
||||
port,
|
||||
secure: port === 465, // implicit TLS on 465, STARTTLS otherwise
|
||||
secure: port === 465, // implicit TLS on 465, STARTTLS otherwise
|
||||
socketTimeout: timeouts.socketMs,
|
||||
})
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user