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.

Author scufre
Recipients scufre
Date 2016-10-07.19:32:57
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1475868777.61.0.59647562301.issue28387@psf.upfronthosting.co.za>
In-reply-to
Content
We have found that you can produce a crash when an instance of _io.TextIOWrapper is being deallocated while there's another thread invoking the garbage collector. I've attached a simple script that should reproduce the issue (textiowrapper_crash.py)

Looking at the code of the _io module, we found that on the dealloc method of the TextIOWrapper class, it first tries to invoke the close method, then releases its internal members, after that removes itself from the garbage collector tracking and finally frees deallocates the remaining stuff. What happens, is that while releasing it's internal members, it might end up calling code that releases the interpreter lock (because its doing an operating system call), letting other threads execute. If for example the thread that comes in, invokes the garbage collector, on debug will raise an assert on gcmodule.c on line 351, where I understand it is complaining that it is tracking an object with refcount 0. In a release build, I suppose this goes on and will end up releasing the object (given it has a refcount of 0), and when the interrupted dealloc thread continues will end up freeing again itself which at some point produces a crash.

Attached is a proposed fix for the issue in textio.c.patch, where the it the call to _PyObject_GC_UNTRACK is now done right after the call to the close method and before release its internal members.

As a reference we have been able to reproduce this with Python 2.7.12 on Windows (i386)
History
Date User Action Args
2016-10-07 19:32:57scufresetrecipients: + scufre
2016-10-07 19:32:57scufresetmessageid: <1475868777.61.0.59647562301.issue28387@psf.upfronthosting.co.za>
2016-10-07 19:32:57scufrelinkissue28387 messages
2016-10-07 19:32:57scufrecreate