This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: socket line buffering
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: kristjan.jonsson Nosy List: 0lejka, BreamoreBoy, ajaksu2, asvetlov, jbrouwers, kristjan.jonsson, pitrou, python-dev
Priority: normal Keywords: patch

Created on 2004-01-18 19:37 by jbrouwers, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
_fileobject.diff kristjan.jonsson, 2012-12-14 11:29
_fileobject.diff kristjan.jonsson, 2012-12-20 13:41
_fileobject23122012.diff 0lejka, 2012-12-23 12:50 review
Messages (11)
msg60460 - (view) Author: Jean M. Brouwers (jbrouwers) Date: 2004-01-18 19:37
There is a bug in the line buffering code in the
Lib/socket.py module.

The write() method in the _fileobject class will flush
the buffered data at every call even if there no new
line character present in the data.

The problem is that the third part of the last if
statement will always be True if self._wbufsize equals 1.

<pre>
  if (self._wbufsize == 0 or
      self._wbufsize == 1 and '\n' in data or
      self._get_wbuf_len() >= self._wbufsize):
      self.flush()
</pre>

A possible fix would be the following:

<pre>
  if (self._wbufsize == 0 or
      self._wbufsize == 1 and '\n' in data or
      self._wbufsize > 1 and self._get_wbuf_len() >=
self._wbufsize):
      self.flush()
</pre>
msg82012 - (view) Author: Daniel Diniz (ajaksu2) * (Python triager) Date: 2009-02-14 11:34
The code described by Jean is still present.
msg114312 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-08-19 00:35
I'm just wondering if the original code could be the cause of subtle bugs with socket.py, anyone?  (I'm no sockets guru). There's a proposed inline patch that's never been implemented, what do you (plural) make of it?.
msg177458 - (view) Author: Kristján Valur Jónsson (kristjan.jonsson) * (Python committer) Date: 2012-12-14 11:29
Here's a patch for the current 2.7 stuff, from issue #16680 (which was deemed duplicate).
Unless anyone objects, I'll commit that to 2.7 soon.  Eight years, this has taken.
msg177464 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-12-14 16:34
Would be nice to add a test...
msg177471 - (view) Author: Kristján Valur Jónsson (kristjan.jonsson) * (Python committer) Date: 2012-12-14 17:09
Good point, will do.
msg177816 - (view) Author: Kristján Valur Jónsson (kristjan.jonsson) * (Python committer) Date: 2012-12-20 13:41
New patch, with unittest.
msg177982 - (view) Author: oleg chubin (0lejka) * Date: 2012-12-23 12:50
I just have updated patch for current version of code. It looks good for me.
msg177986 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2012-12-23 13:47
LGTM.
Kristján, would you like to commit?
msg178020 - (view) Author: Kristján Valur Jónsson (kristjan.jonsson) * (Python committer) Date: 2012-12-23 23:01
Sure, Leave it to me.
msg178123 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-12-25 13:06
New changeset 5be3fa83d436 by Kristján Valur Jónsson in branch '2.7':
issue #879399
http://hg.python.org/cpython/rev/5be3fa83d436
History
Date User Action Args
2022-04-11 14:56:02adminsetgithub: 39835
2012-12-25 13:34:19asvetlovsetstatus: open -> closed
stage: patch review -> resolved
2012-12-25 13:08:05kristjan.jonssonsetresolution: fixed
2012-12-25 13:06:55python-devsetnosy: + python-dev
messages: + msg178123
2012-12-24 10:16:05asvetlovsetassignee: kristjan.jonsson
2012-12-23 23:01:36kristjan.jonssonsetmessages: + msg178020
2012-12-23 13:47:52asvetlovsetmessages: + msg177986
2012-12-23 12:50:020lejkasetfiles: + _fileobject23122012.diff
nosy: + asvetlov, 0lejka
messages: + msg177982

2012-12-20 13:41:41kristjan.jonssonsetfiles: + _fileobject.diff

messages: + msg177816
2012-12-14 17:09:53kristjan.jonssonsetmessages: + msg177471
2012-12-14 16:34:12pitrousetnosy: + pitrou

messages: + msg177464
versions: - Python 3.1, Python 3.2
2012-12-14 11:29:25kristjan.jonssonsetfiles: + _fileobject.diff

nosy: + kristjan.jonsson
messages: + msg177458

keywords: + patch
2012-12-14 10:07:33neologixlinkissue16680 superseder
2010-08-19 00:35:56BreamoreBoysetversions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.6
nosy: + BreamoreBoy

messages: + msg114312

stage: test needed -> patch review
2009-02-14 11:34:54ajaksu2settype: behavior
stage: test needed
messages: + msg82012
nosy: + ajaksu2
versions: + Python 2.6, - Python 2.3
2004-01-18 19:37:59jbrouwerscreate