fix(server): bound alert webhook/SMTP delivery timeouts (JEF-497)#126
Merged
thejefflarson merged 1 commit intoJul 25, 2026
Conversation
alert.notify spans clustered at ~11.5s (11,494/11,604/11,750ms, error_count=0) — slow, not failing — a fixed connect/handshake stall in the delivery path. Both notify() sinks were unbounded: - Webhook used reqwest::Client::new(), which has no request AND no connect timeout, so a slow/unresponsive receiver blocked send() up to the OS TCP timeout. - The lettre AsyncSmtpTransport was built without .timeout(...), so a slow SMTP relay handshake stalled just as long. Because notify() is awaited inside the eval tick (run → evaluate → notify), a stalled sink delayed the whole tick and backed up other rules' notifications. Fix: build the webhook client once with explicit bounds (10s request / 5s connect) via a shared build_webhook_client() helper so run and evaluate_once get identical config; a failed build logs and disables the webhook rather than panicking, matching how a bad SMTP config disables email. Give the SMTP transport .timeout(Some(10s)) in Mailer::build. Values are short enough a dead sink can't stall the loop, long enough for a legitimately slow-but-alive receiver. Test: a local TcpListener that accepts but never responds (the exact hung- receiver case) makes notify() give up in ~10s (measured 10.01s), asserted < 15s — bounded by the request timeout, not the multi-second OS TCP timeout. Re-architecting the loop (spawning notify off the tick / a delivery queue) is a noted follow-up and out of scope here. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JbrmfzHsTMMzPaSrUkZgWo
thejefflarson
deleted the
thejefflarson/jef-497-alertnotify-p99-115s-webhooksmtp-sinks-have-no-timeout-bound
branch
July 25, 2026 23:04
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.
JEF-497 — alert.notify p99 ~11.5s: webhook/SMTP sinks have no timeout
Symptom
alert.notifyspans cluster at ~11.5s (11,494 / 11,604 / 11,750ms) witherror_count=0— slow, not failing: a fixed connect/handshake stall in the alert delivery path (not ingest).Root cause
notify()delivered to two sinks with no timeout:reqwest::Client::new()has neither a request nor a connect timeout, so a slow/unresponsive receiver blockedsend()up to the OS TCP timeout.AsyncSmtpTransportwas built without.timeout(...), so a slow SMTP relay handshake stalled just as long.notify()is awaited inside the eval tick (run → evaluate → notify), so a stalled sink delayed the whole tick and backed up other rules' notifications.Fix
build_webhook_client()helper builds the reqwest client once with explicit bounds — 10s total request / 5s connect — reused by bothrunandevaluate_onceso both delivery paths get identical config. A failedbuild()logs and disables the webhook rather than panicking, matching how a bad SMTP config disables email.Mailer::buildnow sets.timeout(Some(Duration::from_secs(10)))on the SMTP transport.Re-architecting the loop (spawning
notifyoff the tick / a delivery queue) is a noted follow-up and explicitly out of scope here — the timeouts are the fix.Test
notify_gives_up_on_a_hung_webhook_within_timeout: a localtokio::net::TcpListenerthat accepts but never responds (the exact hung-receiver case).notify()gives up in ~10s (measured 10.01s), asserted< 15s— bounded by the request timeout, not the multi-second OS TCP timeout. Deterministic, no real-network dependency.Gates
cargo fmt/cargo check/cargo clippy --all-targets -- -D warnings/cargo test --locked— all green (57 tests incl. the new one).🤖 Generated with Claude Code
https://claude.ai/code/session_01JbrmfzHsTMMzPaSrUkZgWo