classification
Title: Python 2.3+ socket._fileobject handles EAGAIN with data loss
Type: behavior Stage: test needed
Components: Library (Lib) Versions: Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: BreamoreBoy, jnelson, pitrou
Priority: normal Keywords:

Created on 2004-10-01 16:56 by jnelson, last changed 2011-01-04 01:33 by pitrou.

Messages (4)
msg60570 - (view) Author: Jon Nelson (jnelson) Date: 2004-10-01 16:56
If one has a non-blocking socket, 'sock', and uses
'sock.makefile()' to create file-like object out of it,
there exists the possibility (even probability) of data
loss in the event of an EAGAIN error.

The code that comprises _fileobject in socket does not
try to catch EAGAIN.  In the event that the read()
operation does not encounter EOF, but *has* read data
(and then gets an EAGAIN) such as when there is less
than 8KB of data to read, the socket.error traceback is
handed back to the caller of read and the read data is
discarded.  This is horrible. The _fileobject read
routine (and probably write, too) should catch
socket.error and check it for EAGAIN, and in that case,
return what it has already read (if anything). 
msg60571 - (view) Author: Jon Nelson (jnelson) Date: 2004-10-01 18:25
Logged In: YES 
user_id=8446

An improvement would be to allow EAGAIN to surface only if
it happens as the /first/ read. 
msg114378 - (view) Author: Mark Lawrence (BreamoreBoy) Date: 2010-08-19 16:39
Is this still valid?
msg125275 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-01-04 01:33
Should work fine under 3.x.
History
Date User Action Args
2011-01-04 01:33:15pitrousetnosy: + pitrou

messages: + msg125275
versions: - Python 3.1, Python 3.2
2010-08-19 16:39:37BreamoreBoysetnosy: + BreamoreBoy

messages: + msg114378
versions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.6
2009-02-14 18:21:49ajaksu2setstage: test needed
type: behavior
versions: + Python 2.6
2004-10-01 16:56:04jnelsoncreate