Message107925
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) |
|
Date |
User |
Action |
Args |
2010-06-16 15:11:25 | Ruben.Bakker | set | recipients:
+ Ruben.Bakker |
2010-06-16 15:11:25 | Ruben.Bakker | set | messageid: <1276701085.45.0.35769519286.issue9010@psf.upfronthosting.co.za> |
2010-06-16 15:11:23 | Ruben.Bakker | link | issue9010 messages |
2010-06-16 15:11:23 | Ruben.Bakker | create | |
|