Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue7322] Socket timeout can cause file-like readline() method to lose data

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Nov 14, 2009, 9:16 AM

Post #1 of 2 (152 views)
Permalink
[issue7322] Socket timeout can cause file-like readline() method to lose data

New submission from David M. Beazley <beazley [at] users>:

Consider a socket that has had a file-like wrapper placed around it
using makefile()

# s is a socket created previously
f = s.makefile()

Now, suppose that this socket has had a timeout placed on it.

s.settimeout(15)

If you try to read data from f, but nothing is available. You'll
eventually get a timeout. For example:

f.readline() # Now, just wait
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File
"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/socket.
py", line 406, in readline
data = self._sock.recv(self._rbufsize)
socket.timeout: timed out

However, now consider the case where you're reading a line of data, but
the receiver has only received a partial line and it's waiting for the
rest of the data to arrive. For example, type this:

f.readline()

Now, go to the other end of the socket connection and send a buffer with
no newline character. For example, send the message "Hello".

Since no newline character has been received, the readline() method will
eventually fail with a timeout as before. However, if you now retry
the read operation f.readline() and send more data such as the message
"World\n", you'll find that the "Hello" message gets lost. In other
words, the repeated readline() operation discards any buffers
corresponding to previously received line data and just returns the new
data.

Admittedly this is a corner case, but you probably don't want data to be
discarded on a TCP connection even if a timeout occurs.

Hope that makes some sense :-). (It helps to try it out).

----------
components: Library (Lib)
messages: 95245
nosy: beazley
severity: normal
status: open
title: Socket timeout can cause file-like readline() method to lose data
type: behavior
versions: Python 2.6

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7322>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 14, 2009, 12:16 PM

Post #2 of 2 (136 views)
Permalink
[issue7322] Socket timeout can cause file-like readline() method to lose data [In reply to]

Changes by Gregory P. Smith <greg [at] krypto>:


----------
assignee: -> gregory.p.smith
nosy: +gregory.p.smith
priority: -> normal

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7322>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.