[2.x] fix: lower SMTP ping threshold to 20s to survive idle-disconnect from relays#4641
Merged
[2.x] fix: lower SMTP ping threshold to 20s to survive idle-disconnect from relays#4641
Conversation
… relays Symfony's SmtpTransport reuses the SMTP connection across sends within a process, NOOPing the connection only when the inter-message gap exceeds pingThreshold (default 100s). AWS SES has been observed closing idle connections in the 30-90s range, so messages spaced 30-100s apart get written into a dead socket and the relay responds with "451 4.4.2 Timeout waiting for data from client". Set pingThreshold to 20s on the Symfony transport — well under any reasonable relay idle timeout, NOOP overhead is negligible. Fixes #4614
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Symfony's
SmtpTransportreuses the SMTP connection across sends within a process and only NOOPs the connection when the inter-message gap exceedspingThreshold(default 100s). AWS SES has been observed closing idle connections in the 30–90s range, so messages spaced 30–100s apart get written into a dead socket and the relay responds with:The reporter's data (failures clustered late in the lifetime of each long-lived queue worker, never near the start) clearly fingerprints connection-age dependence.
Set
pingThresholdto 20s on the Symfony transport inSmtpDriver::buildTransport()— well under any reasonable relay idle timeout, with negligible NOOP overhead.Fixes #4614
Changes
framework/core/src/Mail/SmtpDriver.php— after building the transport via the factory, call$transport->setPingThreshold(20)(guarded byinstanceof SmtpTransportso the cast is safe even thoughEsmtpTransportFactoryalways produces SMTP transports).Test plan
queue:workwith a moderate trickle of email-bound notifications; confirm the451 4.4.2 Timeouterrors no longer appear instorage/logs/flarum-*.log.No automated test for this — the bug only manifests with a real long-lived SMTP connection against a remote server with idle-disconnect behavior. Reproducing in a unit test would require simulating the transport's connection lifecycle, which is heavyweight relative to the fix.
Notes
mail_smtp_ping_thresholdsetting in a future PR if any operator runs into a relay needing different tuning, but the fixed default handles the common cases (SES, Mailgun, Postmark, Gmail SMTP) without ceremony.