Skip to content

Terminate email send on context cancellation - #41

Merged
umputun merged 1 commit into
masterfrom
fix/email-send-context
Aug 19, 2026
Merged

umputun merged 1 commit into
masterfrom
fix/email-send-context

Conversation

@paskal

@paskal paskal commented Aug 18, 2026 •

Copy link
Copy Markdown
Collaborator

The context was checked once before the send, and the sender applies its timeout to the connection setup only, so an SMTP server which accepts the connection and stalls afterwards blocked Send with no way out: no cancellation, no deadline, and the caller waiting on it. SendContext, added in go-pkgz/email v0.8.0 which master already carries, covers the greeting, the authentication, the body transfer and QUIT.

Cancellation stays visible to the caller: when the context ends mid-transaction the SMTP error alone would not match errors.Is(err, context.Canceled), so the context error is reported alongside it.

The test points a sender at a server which greets and stops answering, and cancels once that server has seen the client's first command, so it always exercises the part after the connection is up. It hangs without the change.

@paskal
paskal force-pushed the fix/email-send-context branch from 9a07066 to 8207431 Compare August 18, 2026 23:23
@coveralls

coveralls commented Aug 18, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 32218488175

Coverage increased (+0.008%) to 96.132%

Details

  • Coverage increased (+0.008%) from the base build.
  • Patch coverage: 5 of 5 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 517
Covered Lines: 497
Line Coverage: 96.13%
Coverage Strength: 227.41 hits per line

💛 - Coveralls

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 32197877304

Coverage decreased (-0.4%) to 96.132%

Details

  • Coverage decreased (-0.4%) from the base build.
  • Patch coverage: 5 of 5 lines across 1 file are fully covered (100%).
  • 2 coverage regressions across 1 file.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

2 previously-covered lines in 1 file lost coverage.

File Lines Losing Coverage Coverage
telegram.go 2 95.86%

Coverage Stats

Coverage Status
Relevant Lines: 517
Covered Lines: 497
Line Coverage: 96.13%
Coverage Strength: 225.17 hits per line

💛 - Coveralls

Context was checked once before the send, and the sender applied its
timeout to the connection setup only, so a server accepting the
connection and stalling afterwards blocked Send with no way out.
SendContext of go-pkgz/email covers the whole SMTP transaction.

Requires go-pkgz/email with SendContext, go.mod bump is not included as
that release is not out yet.
@paskal
paskal force-pushed the fix/email-send-context branch 2 times, most recently from 71c56dc to cc68bc8 Compare August 19, 2026 05:13
@paskal
paskal marked this pull request as ready for review August 19, 2026 05:36
@paskal
paskal requested a review from umputun as a code owner August 19, 2026 05:36
@umputun
umputun merged commit 00060c4 into master Aug 19, 2026
5 checks passed
@umputun
umputun deleted the fix/email-send-context branch August 19, 2026 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants