Repository navigation
Reconnect SMTP hooks after leaving a context manager - #74416
Merged
Merged
Conversation
Repeated notifications can reuse a cached hook whose SMTP session was closed by its previous context. Retaining that client makes the next context skip connection setup and attempt another send on a closed session. The hook must discard the client on context exit, including cleanup failures, so subsequent use can establish a fresh session. Keep cleanup exceptions visible rather than suppressing failures to make reuse work. Regression tests cover synchronous and asynchronous context reuse, close/quit failures, and repeated notification through the cached hook.
Use the existing async SMTP test double so lifecycle assertions do not enforce a newer third-party constructor signature. Set notification connection data as portable JSON instead of requiring SDK Connection.as_json on Airflow 3.0.6. Both failed CI environments are covered locally. All five corrected regressions still fail when context-exit client invalidation is removed, so the compatibility correction preserves their ability to catch the original bug. No production behavior or dependency floors are changed.
shivaam
marked this pull request as ready for review
October 8, 2026 04:42
eladkal
approved these changes
Oct 8, 2026
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.
Reusing an
SmtpHookacross two context-manager blocks retains the closed SMTP client and skips connection setup on the second use. This also affects repeated calls to anSmtpNotifier, which caches its hook.Clear the client reference when synchronous or asynchronous context cleanup finishes, including when
close()orquit()raises, so the next use reconnects. Cleanup errors still propagate to the caller.Regression tests cover repeated sync/async sends, cleanup failures, and repeated notifications using the notifier's real cached hook. All five new cases fail without the fix.
Validation: full SMTP unit suite (59 passed), selected core and provider DB/non-DB regressions (including 299 core and 1,081 provider non-DB passes), hook and all-provider type checks, regular/manual repository hooks, and SMTP/common.compat documentation builds and spell checks. Related setup-failure work is in #74185; this change covers cleanup after context exit.
Was generative AI tooling used to co-author this PR?
Generated-by: Codex (GPT-6) following the guidelines