]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
- Issue #3309: Fix bz2.BZFile itererator to release its internal lock
authorGregory P. Smith <greg@mad-scientist.com>
Mon, 7 Jul 2008 04:31:58 +0000 (04:31 +0000)
committerGregory P. Smith <greg@mad-scientist.com>
Mon, 7 Jul 2008 04:31:58 +0000 (04:31 +0000)
  properly when raising an exception due to the bz2file being closed.
  Prevents a deadlock.

Lib/test/test_bz2.py
Misc/NEWS
Modules/bz2module.c

index b8b3c031027136ced4d167654284cab16ccb0665..c4d9b6968a3426c21e06cccb311dc88f2e054bbf 100644 (file)
@@ -112,6 +112,17 @@ class BZ2FileTest(BaseTest):
         self.assertEqual(list(iter(bz2f)), sio.readlines())
         bz2f.close()
 
+    def testClosedIteratorDeadlock(self):
+        # "Test that iteration on a closed bz2file releases the lock."
+        # http://bugs.python.org/issue3309
+        self.createTempFile()
+        bz2f = BZ2File(self.filename)
+        bz2f.close()
+        self.assertRaises(ValueError, bz2f.next)
+        # This call will deadlock of the above .next call failed to
+        # release the lock.
+        self.assertRaises(ValueError, bz2f.readlines)
+
     def testXReadLines(self):
         # "Test BZ2File.xreadlines()"
         self.createTempFile()
index 2dfa33ab51ff2ba2d3444ddd98b661d4034493d9..c544739aefc04926e23d8ee0c645f383e252a33b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -68,6 +68,10 @@ Library
 - Issue #2113: Fix error in subprocess.Popen if the select system call is
   interrupted by a signal.
 
+- Issue #3309: Fix bz2.BZFile itererator to release its internal lock
+  properly when raising an exception due to the bz2file being closed.
+  Prevents a deadlock.
+
 Build
 -----
 
index bbabe101e58364b4d3a225aa1bc5f6f3c056f06c..16201bd6486c5bfbe66df646ea99553fa0452514 100644 (file)
@@ -1451,6 +1451,7 @@ BZ2File_iternext(BZ2FileObject *self)
        PyStringObject* ret;
        ACQUIRE_LOCK(self);
        if (self->mode == MODE_CLOSED) {
+                RELEASE_LOCK(self);
                PyErr_SetString(PyExc_ValueError,
                                "I/O operation on closed file");
                return NULL;