[New-bugs-announce] [issue9010] Infinite loop in imaplib.IMAP4_SSL when used with Gmail

Ruben Bakker report at bugs.python.org
Wed Jun 16 17:11:25 CEST 2010


New submission from Ruben Bakker <ruben.bakker1 at gmail.com>:

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 at 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)

----------
components: Library (Lib)
messages: 107925
nosy: Ruben.Bakker
priority: normal
severity: normal
status: open
title: Infinite loop in imaplib.IMAP4_SSL when used with Gmail
type: behavior
versions: Python 2.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9010>
_______________________________________


More information about the New-bugs-announce mailing list