Skip to content

notify/email: honour the context when dialing with implicit TLS - #5690

Open
vignesh2027 wants to merge 1 commit into
prometheus:mainfrom
vignesh2027:fix/email-implicit-tls-context
Open

vignesh2027 wants to merge 1 commit into
prometheus:mainfrom
vignesh2027:fix/email-implicit-tls-context

Conversation

@vignesh2027

Copy link
Copy Markdown

Pull Request Checklist

Please check all the applicable boxes.

  • Please list all open issue(s) discussed with maintainers related to this change
    • None, I did not find an existing issue for this.
  • Is this a new Receiver integration?
  • Is this a bugfix?
    • I have added tests that can reproduce the bug which pass with this bugfix applied
  • Is this a new feature?
    • I have added tests that test the new feature's functionality
  • Does this change affect performance?
    • I have provided benchmarks comparison that shows performance is improved or is not degraded
      • You can use benchstat to compare benchmarks
    • I have added new benchmarks if required or requested by maintainers
  • Is this a breaking change?
    • My changes do not break the existing cluster messages
    • My changes do not break the existing api
  • I have added/updated the required documentation
  • I have signed-off my commits
  • I will follow best practices for contributing to this project

The email notifier connects with net.Dialer.DialContext when it uses plain SMTP or STARTTLS, but with tls.Dial when implicit TLS is used (port 465 or force_implicit_tls: true). tls.Dial has no timeout and does not look at the context.

If the smarthost accepts the TCP connection but never finishes the TLS handshake, Notify stays blocked even after the notification context is done. The existing TestEmailNotifyWithDoneContext covers this for the plain path only.

This change uses tls.Dialer.DialContext, so the dial and the handshake both stop when the context ends. The new test starts a listener that accepts connections and never writes, then calls Notify with a 100ms context timeout. On main it is still blocked after 5 seconds. With the fix it returns establish TLS connection to server: ... right after the timeout.

Which user-facing changes does this PR introduce?

[BUGFIX] email: Stop waiting on the implicit TLS handshake when the notification context is done.

The plain SMTP path dials with DialContext, but the implicit TLS path
used tls.Dial, which has no timeout and ignores the context. A smarthost
that accepts the TCP connection but never completes the TLS handshake
blocked the notification with no limit.

Use tls.Dialer.DialContext so both the dial and the handshake stop when
the notification context is done.

Signed-off-by: vigneshwar <applemacbook6sep2004@gmail.com>
@vignesh2027
vignesh2027 requested a review from a team as a code owner October 25, 2026 12:17
@coderabbitai

coderabbitai Bot commented Oct 25, 2026

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 294c544 and 4afd4fb.

Files selected for processing: 2
  • notify/email/email.go
  • notify/email/email_test.go

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

Walkthrough

When implicit TLS is enabled, Email.Notify now uses the notification context to dial the TLS connection. A new test checks that context cancellation during a stalled TLS handshake returns an error within five seconds.

Changes: Email notification TLS context

Layer / File(s) Summary
Context-aware implicit-TLS dialing
notify/email/email.go, notify/email/email_test.go
Email.Notify uses tls.Dialer.DialContext with the notification context for implicit-TLS connections. The test checks cancellation during a stalled handshake and requires the call to return within five seconds.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: Minimal · up to 4afd4

Implicit-TLS notification dialing now honors cancellation, and no actionable merge risk is identified.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly identifies the email notifier area and explains that implicit TLS now honors the context during dialing.
Description check Passed The description is complete and relevant. It explains the bug, the implementation, the regression test, compatibility impact, checklist status, and release note.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants