fix(mail): SMTP send retry (2x2s) + 502 on verification-code send failure (rant 2026-08-21T23:52:17) - #112
Merged
Conversation
…lure (rant 2026-08-21T23:52:17) - mail.rs: send_with_retry helper (1 initial + 2 retries, fixed 2s delay, fresh transport per attempt — Gmail silently drops datacenter IPs intermittently; app-level fault tolerance) - routes send_code: on final SMTP failure, clear the verification record (releases the 60s resend rate limit so the user can retry immediately) and return 502 + clear actionable error instead of 500 - tests: 3 retry unit tests (success after failures / no infinite retry / last-error returned) + register_smtp_failure_502 integration test (unreachable SMTP → 502; resend right after is not rate-limited) - 136/136 tests + fmt + clippy clean
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
Fault tolerance for the verification-code email path per host rant
2026-08-21T23:52:17(project=aitokenpool). Gmail (and similar providers) intermittently and silently drop connections from datacenter IPs (Alibaba/Tencent Cloud etc.) — TCP/TLS succeed but the SMTP banner never arrives, lettre times out after 15s, HTTP 500. This is external-service unreliability, so the fix is app-level:src/mail.rs): newsend_with_retryhelper — 1 initial attempt + up to 2 retries with a fixed 2s delay, fresh transport per attempt (new TCP+TLS connection, matching the observed transient-drop pattern). Errors only after all 3 attempts fail.src/routes/mod.rssend_code): on final SMTP failure, the verification record is cleared (releases the 60s resend rate limit, so the user can resend immediately instead of being stuck) and the API returns 502 + 「验证码发送失败,请重试」 (was 500) — register/resend/forgot-password all benefit.Related Issue
Host rant
2026-08-21T23:52:17.109049+08:00(project=aitokenpool), verbatim:Changes
Tests
cargo test— 136/136 passed (132 + 4 new)cargo fmt --check— cleancargo clippy --all-targets -- -D warnings— cleanChecklist
fix/smtp-retry)