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.

Author Ruben.Bakker
Recipients Ruben.Bakker
Date 2010-06-16.15:11:23
SpamBayes Score 0.019427681
Marked as misclassified No
Message-id <1276701085.45.0.35769519286.issue9010@psf.upfronthosting.co.za>
In-reply-to
Content
When using imaplib.IMAP4_SSL to open a Gmail mailbox, the readline method can go into a infinite loop. It happens after Gmail drops the connection, usually after some time/inactivity. The next imaplib request will cause the infinite loop inside the readline() method.

Steps to reproduce:
Perform this script (use python -i to get the prompt):

import imaplib

HOST="imap.gmail.com"
PORT=993
USERNAME="username@gmail.com"
PASSWORD="password"

server = imaplib.IMAP4_SSL(host=HOST, port=PORT)
server.login(USERNAME, PASSWORD)

def f():
	print server.select("INBOX")
	print server.uid("FETCH", "1:*", "(UID FLAGS BODY.PEEK[HEADER.FIELDS (Subject)])")

Call the f() function and then wait about about an hour. Call f() again and server.select() will not return but take all CPU.

Add this line in IMAP4_SSL
          if not char: raise self.abort('socket error: EOF')

complete method:
    def readline(self):
        """Read line from remote."""
        line = []
        while 1:
            char = self.sslobj.read(1)
            if not char: raise self.abort('socket error: EOF')
            line.append(char)
            if char == "\n": return ''.join(line)
History
Date User Action Args
2010-06-16 15:11:25Ruben.Bakkersetrecipients: + Ruben.Bakker
2010-06-16 15:11:25Ruben.Bakkersetmessageid: <1276701085.45.0.35769519286.issue9010@psf.upfronthosting.co.za>
2010-06-16 15:11:23Ruben.Bakkerlinkissue9010 messages
2010-06-16 15:11:23Ruben.Bakkercreate