[New-bugs-announce] [issue5565] Strange behavior when I logout() with IMAP4_SSL

Philipp Tölke <report@bugs.python.org> at psf.upfronthosting.co.za Philipp Tölke <report@bugs.python.org> at psf.upfronthosting.co.za
Thu Mar 26 08:12:25 CET 2009

New submission from Philipp Tölke <toelke+pb at model.in.tum.de>:

While researching some strange logs from out firewall and narrowing it
down to a biff-like imap-client written in python we found the following:

To reproduce:

Start a network-sniffer like wireshark on the loopback-interface
In one shell start some network-listener:
$ nc -l -p 12345

In python, connect to it and send some data:
>>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> s.connect(("", 12345))
>>> s.send("Hallo\n");

The other shell now looks like:
$ nc -l -p 12345

Type in anything and press <Enter> to send. Then quit the nc with C-c.

>>> s.close()

What I see here is the following:
The two messages are exchanged and nc sends his FIN-Package when
quitting. Python ACKnowledges this package (though intrestingly enough,
with a ack-number one to far (8 instead of 7 in my example)). At the
Moment of the s.close(), it sends another package, containing the same
ACK-Number, the same SEQ-Number(!) and this time the RST-Flag as well.

If I understand correctly, it sends RST, because not everything from the
connection was read by python. Why does it resend the ACK? Why is the
ACK-Number one to high? Why does it reuse the SEQ-Number?

And now to imaplib.IMAP4_SSL. The behavior here seems to me even more

If I invoke .logout(), the server sends his "BYE" message and after that
a FIN, which python ACKnowledges. At the moment, that the
IMAP4_SSL-object gets out of scope, a RST/ACK-Package is send, that
again re-ACKs the FIN and has the same sequence-number, that the ACK
package had!

Why does .logout() not send a FIN? Why does it not read the complete
Buffer, so that the Socket could close with FIN? And, why does it wait
until getting out of scope with sending this RST? (I assume, that is
when the Object is garbage-collected)

Thank you!

components: Library (Lib)
messages: 84175
nosy: toelke
severity: normal
status: open
title: Strange behavior when I logout() with IMAP4_SSL
versions: Python 2.5

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list