This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: patch smtplib:when SMTPDataError, rset crashes with sslerror
Type: behavior Stage: test needed
Components: Library (Lib) Versions: Python 3.7, Python 3.6, Python 3.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: barry, christian.heimes, hwundram, jesstess, kxroberto, r.david.murray, terry.reedy, zvyn
Priority: normal Keywords: patch

Created on 2006-05-03 11:59 by kxroberto, last changed 2022-04-11 14:56 by admin.

Files
File name Uploaded Description Edit
smtplib_nosideeffecterror.patch kxroberto, 2010-08-23 10:38
issue1481032.patch zvyn, 2014-07-23 23:52 review
Messages (10)
msg50175 - (view) Author: kxroberto (kxroberto) Date: 2006-05-03 11:59

  File "smtplib.pyc", line 690, in sendmail
  File "smtplib.pyc", line 445, in rset
  File "smtplib.pyc", line 370, in docmd
  File "smtplib.pyc", line 344, in getreply
  File "smtplib.pyc", line 159, in readline
sslerror: (8, 'EOF occurred in violation of protocol')

traced from a py2.3 - yet unchanged.  

=> hides original error SMTPDataError. such
SMTPDataError may have forced a disconnect of server. 

patch for py2.3,py2.4,..

( I have this patch in my MUST-DO-PATCHes after any
Python installation. )

--

the patch passes on any error in this rset() location.
it also patches a error in PLAIN authentication

could cleanly catch socket.sslerror / socket.error /
EnvironmentError, yet ssl not always there ... 
rset() is tested otherwise, so the nacked except is ok?

(there should maybe be special a common base Exception
class "IOBaseError" for :   EnvironmentError(IOError,
OSError),  EOFError, socket.error, socket.sslerror,
ftplib.all_errors, etc.  Nice as it and not all IO
sublibs have to be imported to catch such errors.)

---

the same problem is with smtp.quit() on many SSL'ed
connections (without any other errors occuring): a
final socket.sslerror is raised during quit(). 
There may be a problem in the termination code of
ssl-FakeSockets or ssl.c . Or the same type of error
catch (on IOBaseError) should be applied. I am not sure
 - in my apps I (must) catch on smtp.quit() generally. 

(Compare also bug #978833 / shutdown(2)-remedy in
httplib's SSL FakeSocket - this shutdown(2) remedy
patch of #978833 I still have it on my MUST list
(py2.3/py2.4 installations), otherwise this FakeSocket
doesn't close fully in a FTPS application (where
termination on data channel is crucial for getting
response on the control channel) - and most likely puts
tremendous connection load on HTTPS servers because of
stale unterminated HTTPS connections while the bug may
not be obvious in casual usage. I'm not completely
clear about the nature of this error. Thus, what I say
is based on trial-and-error.

-robert
msg50176 - (view) Author: Heiko Wundram (hwundram) Date: 2006-05-05 06:55
Logged In: YES 
user_id=791932

Where is the patch? :-)
msg50177 - (view) Author: kxroberto (kxroberto) Date: 2006-05-05 10:22
Logged In: YES 
user_id=972995

here (i forgot the upload checkbox?)
msg114657 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-08-22 10:07
The change to the encode_plain method in the patch was done via #1075928 on 2004-12-06.  The try/except change around a call to self.rset() was never implemented.
msg114734 - (view) Author: kxroberto (kxroberto) Date: 2010-08-23 10:30
still I think all 3 self.rset()'s in SMTP.sendmail, which are followed by a raise <someerror> statement have to be bracketed with an except clause or so - nowadays better like """
try: self.res()
except (EnvironmentError, SMTPException):
    pass
""",  as all socket.error, sslerror seem meanwhile correctly inherited (via IOError).

Because the original error must pop up, not a side effect of state cleaning!
msg147683 - (view) Author: kxroberto (kxroberto) Date: 2011-11-15 15:19
ping!
perhaps I forgot to write that I uploaded the cleaned patch also on 2010-08-23. I really think this simple patch is necessary. Just seen the same problem again - as I forgot the patch in one of my recent Python update installations.

When SMTPDataError, SMTPRecipientsRefused, SMTPSenderRefused should be raised, very likely a subsequent error (like closed connection etc.) overlappes the original Exception during self.rset(), and one will not be able to locate the problem on user level in eons ..

This patch is still in my vital-patches collection which I have to apply after every Python update since years.
msg223800 - (view) Author: Milan Oberkirch (zvyn) * Date: 2014-07-23 23:52
This bug was resolved for SMTPServerDisconnected exceptions but not for SSLError. Is it still reproducible? If so, the attached patch should fix it for 3.x (couldn't test if it does because I don't know how to reproduce the error).
msg226087 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-08-29 21:20
David, do you agree with either of the proposed changes?
msg226101 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-08-29 23:02
Milan's patch should be correct.  It would be nice to have a reproducer.
msg275036 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2016-09-08 15:03
Is this still an issue? The bug is 10 years old and the patch two years.
History
Date User Action Args
2022-04-11 14:56:17adminsetstatus: pending -> open
github: 43311
2016-09-08 15:03:02christian.heimessetstatus: open -> pending
versions: + Python 3.6, Python 3.7, - Python 2.7, Python 3.4
nosy: + christian.heimes

messages: + msg275036
2014-08-29 23:02:55r.david.murraysetmessages: + msg226101
2014-08-29 21:20:27terry.reedysetnosy: + terry.reedy

messages: + msg226087
versions: + Python 3.4, Python 3.5, - Python 2.6, Python 3.1, Python 3.2
2014-07-23 23:52:55zvynsetfiles: + issue1481032.patch
nosy: + zvyn, jesstess
messages: + msg223800

2011-11-16 13:27:39pitrousetnosy: + barry, r.david.murray, - BreamoreBoy
2011-11-15 15:19:29kxrobertosetmessages: + msg147683
2010-08-23 10:39:17kxrobertosetfiles: - smtplib-authplain-tryrset.patch
2010-08-23 10:38:57kxrobertosetfiles: + smtplib_nosideeffecterror.patch
2010-08-23 10:30:12kxrobertosetmessages: + msg114734
versions: + Python 2.6
2010-08-22 10:07:56BreamoreBoysetnosy: + BreamoreBoy

messages: + msg114657
versions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.6
2009-03-21 02:44:55ajaksu2setstage: test needed
type: behavior
versions: + Python 2.6, - Python 2.4
2006-05-03 11:59:13kxrobertocreate