Message102261
$ cat /tmp/test.py
import socket
SIZE = 1000000000L
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
s.recv(SIZE)
finally:
s.close()
$ python /tmp/test.py
Traceback (most recent call last):
File "/tmp/test.py", line 8, in <module>
s.recv(SIZE)
MemoryError
$ strace python /tmp/test.py
[...]
socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 3
mmap2(NULL, 1000001536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = -1 ENOMEM (Cannot allocate memory)
brk(0x4440c000) = 0x8a56000
mmap2(NULL, 1000132608, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = -1 ENOMEM (Cannot allocate memory)
mmap2(NULL, 2097152, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0) = 0xb79b1000
munmap(0xb79b1000, 323584) = 0
munmap(0xb7b00000, 724992) = 0
mprotect(0xb7a00000, 135168, PROT_READ|PROT_WRITE) = 0
mmap2(NULL, 1000001536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = -1 ENOMEM (Cannot allocate memory)
[...]
imaplib is simply requesting too much at a time: the memory error is probably raised in Modules/socketmodule.c:sock_recv
/* Allocate a new string. */
buf = PyString_FromStringAndSize((char *) 0, recvlen);
if (buf == NULL)
return NULL;
Requesting a 10M read is indeed quite questionable, and will fail no matter what system is used (the limit will depend on the heap usage and OS, though).
The fix should be made at imaplib level, rather than requiring users to redefine IMAP4 read method. A patch is attached (imaplib_read.diff). |
|
Date |
User |
Action |
Args |
2010-04-03 13:39:17 | neologix | set | recipients:
+ neologix, mcicogni, taukki, vila, elachuni, anglocelt, r.david.murray, marcio, trogdorsey |
2010-04-03 13:39:16 | neologix | set | messageid: <1270301956.96.0.536341826844.issue1441530@psf.upfronthosting.co.za> |
2010-04-03 13:39:15 | neologix | link | issue1441530 messages |
2010-04-03 13:39:14 | neologix | create | |
|