Opened 3 years ago

Closed 3 years ago

#19134 closed Cleanup/optimization (fixed)

Can't close SMTP connection, when already disconnected.

Reported by: sebastian_noack Owned by: nobody
Component: Core (Mail) Version: 1.4
Severity: Normal Keywords:
Cc: hongshuning@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no


When the server has closed the SMTP connection (that happens rather quickly with most SMTP servers if you don't send any command for a few seconds), the exception SMTPServerDisconnected will be raised when trying to use the connection. That also happens when calling .quit(), like the SMTP backend does in its close() method.
So I have written a patch that catches SMTPServerDisconnected in addition to socket.sslerror, while closing the SMTP connection.

Attachments (2)

0001-Handle-SMTPServerDisconnected-in-EmailBackend.close.patch (1.1 KB) - added by sebastian_noack 3 years ago.
19134-with-test.diff (1.3 KB) - added by hongshuning 3 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 3 years ago by claudep

  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to Cleanup/optimization

Thanks for the report. It would be nice to have a test for this. It's always a bit heary to simulate SMTP connections in the test suite, but I've been able to reproduce it with:

backend = smtp.EmailBackend()
backend.username = None # So as it does not try to login

Changed 3 years ago by hongshuning

comment:2 Changed 3 years ago by hongshuning

I write the test case according to claudep's suggest.

comment:3 Changed 3 years ago by hongshuning

  • Cc hongshuning@… added
  • Easy pickings set
  • Needs tests unset

comment:4 Changed 3 years ago by Claude Paroz <claude@…>

  • Resolution set to fixed
  • Status changed from new to closed

In 4081042ef51c0e679c78f2d0d13514af3434ed13:

[1.5.x] Fixed #19134 -- Allowed closing smtp backend when the server is stopped

Thanks Sebastian Noack for the report and the initial patch.
Backport of 1b3f832ab7 from master.

Note: See TracTickets for help on using tickets.
Back to Top