summaryrefslogtreecommitdiffstats
path: root/Lib/smtpd.py
diff options
context:
space:
mode:
authorGiampaolo RodolĂ  <g.rodola@gmail.com>2010-08-23 22:48:51 (GMT)
committerGiampaolo RodolĂ  <g.rodola@gmail.com>2010-08-23 22:48:51 (GMT)
commit8664d74966035c17d1582c19df199f7ad0beef3d (patch)
treeefe22340f401e30cc5bb0b93ce3d0e2beaf6a152 /Lib/smtpd.py
parent63308d7c083e42064e185f3866d8ba15d1faa69a (diff)
downloadcpython-8664d74966035c17d1582c19df199f7ad0beef3d.zip
cpython-8664d74966035c17d1582c19df199f7ad0beef3d.tar.gz
cpython-8664d74966035c17d1582c19df199f7ad0beef3d.tar.bz2
Merged revisions 84289 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r84289 | giampaolo.rodola | 2010-08-24 00:28:13 +0200 (mar, 24 ago 2010) | 1 line fix issue 9129: adds proper error handling on accept() when smtpd accepts new incoming connections. ........
Diffstat (limited to 'Lib/smtpd.py')
-rwxr-xr-xLib/smtpd.py25
1 files changed, 23 insertions, 2 deletions
diff --git a/Lib/smtpd.py b/Lib/smtpd.py
index c3bd6a5..2d17b8d 100755
--- a/Lib/smtpd.py
+++ b/Lib/smtpd.py
@@ -121,7 +121,15 @@ class SMTPChannel(asynchat.async_chat):
self.__rcpttos = []
self.__data = ''
self.__fqdn = socket.getfqdn()
- self.__peer = conn.getpeername()
+ try:
+ self.__peer = conn.getpeername()
+ except socket.error, err:
+ # a race condition may occur if the other end is closing
+ # before we can get the peername
+ self.close()
+ if err[0] != errno.ENOTCONN:
+ raise
+ return
print >> DEBUGSTREAM, 'Peer:', repr(self.__peer)
self.push('220 %s %s' % (self.__fqdn, __version__))
self.set_terminator('\r\n')
@@ -291,7 +299,20 @@ class SMTPServer(asyncore.dispatcher):
localaddr, remoteaddr)
def handle_accept(self):
- conn, addr = self.accept()
+ try:
+ conn, addr = self.accept()
+ except TypeError:
+ # sometimes accept() might return None
+ return
+ except socket.error, err:
+ # ECONNABORTED might be thrown
+ if err[0] != errno.ECONNABORTED:
+ raise
+ return
+ else:
+ # sometimes addr == None instead of (ip, port)
+ if addr == None:
+ return
print >> DEBUGSTREAM, 'Incoming connection from %s' % repr(addr)
channel = SMTPChannel(self, conn, addr)