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.

Title: 2.6.6 rc1 flush() calls del on unbound 'view' variable
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.6
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 2022-04-11 14:57 by admin. This issue is now closed.

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:

Tail end of the runtime stack trace:

  File "/usr/lib/python2.6/", line 318, in write
  File "/usr/lib/python2.6/", 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:
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: <>

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)

t = threading.Thread(target=read_byte_then_close, args=(sock_b,))

file_a = sock_a.makefile('w')

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)
file_a = sock_a.makefile('w')
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.
Date User Action Args
2022-04-11 14:57:05adminsetgithub: 53752
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