sock.makefile().flush has UnboundLocalError bug

Bug #615240 reported by Andrew Bennetts
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Python
Fix Released
Unknown
python2.6 (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

Binary package hint: python2.6

Sometimes calling .write/.writelines/.flush on an object returned from sock.makefile() gives a traceback ending with:

  File "/usr/lib/python2.6/socket.py", line 302, in flush
    del view, data # explicit free
UnboundLocalError: local variable 'view' referenced before assignment

This script demonstrates, but I've seen this with e.g. bzr's test suite too:

"""
import socket
import sys
import threading

sock_a, sock_b = socket.socketpair()
sock_a = socket.socket(_sock=sock_a)

def read_byte_then_close(s):
    data = s.recv(1)
    print >>sys.stderr, 'read:', repr(data)
    s.close()
    print >>sys.stderr, 'closed sock_b'
t = threading.Thread(target=read_byte_then_close, args=(sock_b,))
t.start()

file_a = sock_a.makefile('w')
file_a.writelines(['a'*8192]*1000)
file_a.flush()
t.join()
"""

(It might not be a strictly minimal reproduction, but it's not too far off.)

The cause of the bug is pretty trivially obvious on inspection: the 'view' variable is indeed never defined in that method. Running pyflakes on socket.py finds that bug on line 302, and also a similar one on line 399 in the read() method.

ProblemType: Bug
DistroRelease: Ubuntu 10.10
Package: python2.6 2.6.6~rc1-1ubuntu1
ProcVersionSignature: Ubuntu 2.6.35-14.19-generic 2.6.35
Uname: Linux 2.6.35-14-generic i686
Architecture: i386
Date: Mon Aug 9 16:55:04 2010
InstallationMedia: Ubuntu 10.04 LTS "Lucid Lynx" - Release i386 (20100429)
ProcEnviron:
 LANG=en_AU.utf8
 SHELL=/bin/bash
SourcePackage: python2.6

Revision history for this message
Andrew Bennetts (spiv) wrote :
Revision history for this message
Martin Packman (gz) wrote :
Revision history for this message
Andrew Bennetts (spiv) wrote :

(On closer inspection the second pyflakes report about 'del data' in _fileobject.read() is spurious.)

Changed in python:
status: Unknown → New
Changed in python:
status: New → Fix Released
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package python2.6 - 2.6.6~rc2-1ubuntu1

---------------
python2.6 (2.6.6~rc2-1ubuntu1) maverick; urgency=low

  * Merge with Debian; remaining changes:
    - Regenerate the control file.

python2.6 (2.6.6~rc2-1) unstable; urgency=low

  * Python 2.6.6 release candidate 2.
    - Fix issue #8688: Revert regression introduced in 2.6.6rc1 (making
      Distutils recalculate MANIFEST every time).
    - Fix issue #9543: Fix regression in socket.py introduced in
      Python 2.6.6 rc1 in r83624. LP: #615240.
    - Fix issue #7567: Don't call `setupterm' twice.
  * Update README for python2.6-minimal. Closes: #593391.
 -- Matthias Klose <email address hidden> Wed, 18 Aug 2010 10:01:24 +0200

Changed in python2.6 (Ubuntu):
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.