Code

#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

Description

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 21 months ago.
19134-with-test.diff (1.3 KB) - added by hongshuning 19 months ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 21 months 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
backend.open()
SMTPBackendTests.server.stop()
backend.close()

Changed 19 months ago by hongshuning

comment:2 Changed 19 months ago by hongshuning

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

comment:3 Changed 19 months ago by hongshuning

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

comment:4 Changed 18 months 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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.