classification
Title: 2.6.6 rc1 socket.py flush() calls del on unbound 'view' variable
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ezio.melotti Nosy List: barry, dil, ezio.melotti, gz, r.david.murray, spiv
Priority: release blocker Keywords: needs review, patch

Created on 2010-08-09 01:35 by dil, last changed 2010-08-12 17:29 by ezio.melotti. This issue is now closed.

Files
File name Uploaded Description Edit
issue9543.diff ezio.melotti, 2010-08-11 08:01 fix + test
Messages (9)
msg113357 - (view) Author: David I. Lehn (dil) Date: 2010-08-09 01:35
An error was introduced in 2.6.6 rc1 in the socket flush() call where del is called on the unbound 'view' variable.

Associated commit and diff:

http://svn.python.org/view?view=rev&revision=83624
http://svn.python.org/view/python/tags/r266rc1/Lib/socket.py?r1=81488&r2=83624

Tail end of the runtime stack trace:

  File "/usr/lib/python2.6/socket.py", line 318, in write
    self.flush()
  File "/usr/lib/python2.6/socket.py", line 302, in flush
    del view, data  # explicit free
UnboundLocalError: local variable 'view' referenced before assignment
msg113359 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-08-09 02:09
Thank you very much for testing the alpha and making a report.  I've added Ezio to nosy since he backported the patch, and Barry since he's release manager.
msg113397 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2010-08-09 07:42
Thanks for the report and for figuring out what was the cause!
Indeed the "view" added after the "del" shouldn't be there, so I will remove it.
It would also be great if you could provide a minimal script to reproduce the problem so that it can be turned to a test. None of the tests in the current test suite seem to go through that code path, so the error passed unnoticed.
msg113398 - (view) Author: Martin (gz) * Date: 2010-08-09 08:03
spiv wrote a script to repo the issue in the downstream ubuntu bug:
https://bugs.launchpad.net/python/+bug/615240
msg113399 - (view) Author: Andrew Bennetts (spiv) Date: 2010-08-09 08:06
I have a reproduction script on the Ubuntu bug report I just filed for this issue: <https://bugs.launchpad.net/ubuntu/+source/python2.6/+bug/615240>

Pasting here for convenience:

"""
import socket
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)
    s.close()

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's not quite good enough to add to the test suite yet IMO, but it's a starting point.
msg113408 - (view) Author: Andrew Bennetts (spiv) Date: 2010-08-09 12:05
Chatting with Taggnostr on IRC I've trimmed that reproduction down to something much cleaner (no magic numbers or threads involved):

import socket
sock_a, sock_b = socket.socketpair()
sock_a = socket.socket(_sock=sock_a)
sock_b.close()
file_a = sock_a.makefile('w')
file_a.write('x')
file_a.flush()
msg113590 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2010-08-11 08:01
Here is the patch.
msg113690 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2010-08-12 17:27
Patch accepted, please apply for 2.6.6.
msg113691 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2010-08-12 17:29
Done in r83964.
History
Date User Action Args
2010-08-12 17:29:55ezio.melottisetstatus: open -> closed
resolution: accepted -> fixed
messages: + msg113691

stage: patch review -> resolved
2010-08-12 17:27:30barrysetresolution: accepted
messages: + msg113690
2010-08-11 08:01:20ezio.melottisetkeywords: + patch, needs review
files: + issue9543.diff
messages: + msg113590

stage: test needed -> patch review
2010-08-09 12:05:41spivsetmessages: + msg113408
2010-08-09 08:06:35spivsetnosy: + spiv
messages: + msg113399
2010-08-09 08:03:58gzsetnosy: + gz
messages: + msg113398
2010-08-09 07:42:00ezio.melottisetassignee: ezio.melotti
messages: + msg113397
2010-08-09 02:09:38r.david.murraysetpriority: normal -> release blocker

nosy: + barry, ezio.melotti, r.david.murray
messages: + msg113359

type: crash -> behavior
stage: test needed
2010-08-09 01:35:23dilcreate