Skip to content

bpo-31061: fix crash in asyncio speedup module #2966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Aug 2, 2017
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Include/objimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ PyAPI_FUNC(PyObject *) _PyObject_GC_Calloc(size_t size);
#endif /* !Py_LIMITED_API */
PyAPI_FUNC(PyObject *) _PyObject_GC_New(PyTypeObject *);
PyAPI_FUNC(PyVarObject *) _PyObject_GC_NewVar(PyTypeObject *, Py_ssize_t);

/*
See description in Doc/c-api/gcsupport.rst
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove it.
We can reach the document easily with searching API name.

PyAPI_FUNC(void) PyObject_GC_Track(void *);
PyAPI_FUNC(void) PyObject_GC_UnTrack(void *);
PyAPI_FUNC(void) PyObject_GC_Del(void *);
Expand Down
12 changes: 12 additions & 0 deletions Lib/test/test_asyncio/test_futures.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Tests for futures.py."""

import concurrent.futures
import gc
import re
import sys
import threading
Expand All @@ -19,9 +20,11 @@
def _fakefunc(f):
return f


def first_cb():
pass


def last_cb():
pass

Expand Down Expand Up @@ -483,6 +486,15 @@ def test_future_iter_throw(self):
Exception("elephant"), Exception("elephant"))
self.assertRaises(TypeError, fi.throw, list)

def test_future_del_collect(self):
class Evil:
def __del__(self):
gc.collect()

for i in range(100):
fut = self._new_future(loop=self.loop)
fut.set_result(Evil())


@unittest.skipUnless(hasattr(futures, '_CFuture'),
'requires the C _asyncio module')
Expand Down
2 changes: 2 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ What's New in Python 3.7.0 alpha 1?
Core and Builtins
-----------------

- bpo-31061: Fixed a crash when using asyncio and threads.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last nit: the change in Misc/NEWS needs to be reverted, we need only blurb file.


- bpo-30814: Fixed a race condition when import a submodule from a package.

- bpo-30736: The internal unicodedata database has been upgraded to Unicode
Expand Down
4 changes: 4 additions & 0 deletions Modules/_asynciomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,8 @@ FutureObj_dealloc(PyObject *self)
}
}

PyObject_GC_UnTrack(self);

if (fut->fut_weakreflist != NULL) {
PyObject_ClearWeakRefs(self);
}
Expand Down Expand Up @@ -1846,6 +1848,8 @@ TaskObj_dealloc(PyObject *self)
}
}

PyObject_GC_UnTrack(self);

if (task->task_weakreflist != NULL) {
PyObject_ClearWeakRefs(self);
}
Expand Down