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
+27
-2
@@ -453,7 +453,8 @@ Limits are kept in memory by default, separately for each instance. Several inst
|
||||
`turnstile`, rejected **before** storing. Keys not set → the widget does not
|
||||
show, and the check is skipped. Details: [turnstile.md](./turnstile.md).
|
||||
3. **Validation** against the form definition from the panel (+ enforced GDPR consent).
|
||||
4. **Storing** the submission (form-submissions) → the form-builder sends the emails from the Emails tab.
|
||||
4. **Storing** the submission (form-submissions) → the form-builder composes the emails from the Emails tab;
|
||||
they go out right after the submission is saved ("When e-mails go out").
|
||||
|
||||
**A stored submission = success, even when the email fails** — Payload logs the sending error,
|
||||
the submission data is not lost (it is in Form Submissions).
|
||||
@@ -474,6 +475,29 @@ body (placeholders: `{{field}}`, `{{*}}`, `{{*:table}}`) without touching the co
|
||||
`submitForm` is responsible only for Turnstile verification and storing. It stores the submission in the page's language
|
||||
(`locale` from `createSubmitAction`), so the form-builder takes the email texts and labels in that language.
|
||||
|
||||
### When e-mails go out (`emailsInTransaction`)
|
||||
|
||||
By default (since 1.17.0) a form's e-mails go out **right after the submission is saved**: they are composed inside
|
||||
the submission's database transaction (layout, `forms.beforeEmail`, the kind marks, all with the transaction's
|
||||
`req`), and handed to the mail server once that transaction has committed and given its connection back — still
|
||||
within the same request, so `submitForm` answers as before (a file that could not be sent is still reported to the
|
||||
visitor). What this changes:
|
||||
|
||||
- a slow or hanging mail server holds **no database connection** — on Postgres, many submissions at once used to stop
|
||||
the site ([deployment.md](./deployment.md) §4.3a);
|
||||
- a submission whose transaction is **rolled back** (a later hook of yours throws) sends **nothing**; before, its
|
||||
e-mails had already gone out;
|
||||
- **a failure after the commit leaves a stored submission without its e-mail** (the mail server refused it, or the
|
||||
process ended in between) — as an e-mail failure always did: the submission is in Form Submissions, the error in
|
||||
the log and the panel status, a file marked **File delivery: Not sent**;
|
||||
- `payload.create` of a submission inside **your own transaction** (`req` passed from a hook or a script): the e-mails
|
||||
go out when that transaction commits, and not at all when it is rolled back;
|
||||
- **MongoDB without a replica set, SQLite** (no transactions): sent at once, exactly as before.
|
||||
|
||||
`forms: { emailsInTransaction: true }` sends them inside the transaction, as before 1.17.0 (not recommended on
|
||||
Postgres). Building blocks: `sendAfterCommit(prepare, deliver)` (the `beforeEmail` that does this),
|
||||
`sendFormEmails(req, emails)` (form-builder's own send loop), `afterCommit(req, fn)` (deployment.md §4.3a).
|
||||
|
||||
### Nice emails (`emailLayout`)
|
||||
|
||||
```ts
|
||||
@@ -848,6 +872,7 @@ filter it out on the client.
|
||||
site-wide consent field name: `forms.consentFieldName`; shared limit store: `setRateLimitStore`; missing IP: `setUnknownIpFactor`.
|
||||
- **Check:** `POST /api/form-submissions` without a session = 403; a `user` account → `PATCH /api/forms/<id>` = 403;
|
||||
submits without an IP header → past `maxPerMinute × 20` per minute (100 by default) you get `rate_limited`.
|
||||
- **Emails:** `forms.beforeEmail` modifies emails (after the layout), `emailLayout: true` turns on the template.
|
||||
- **Emails:** `forms.beforeEmail` modifies emails (after the layout), `emailLayout: true` turns on the template,
|
||||
`emailsInTransaction: true` sends them inside the submission's transaction ("When e-mails go out").
|
||||
- **Your own front end:** `BuilderForm` (`renderField`), `useBuilderForm`, pure logic (`splitSteps`,
|
||||
`visibleFields`, `validateBuilderFields`…), `useForm` / `useContactForm`, validators, `buildFormsPlugin` (root).
|
||||
|
||||
Reference in New Issue
Block a user