summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2018-10-13 19:26:47 (GMT)
committerNed Deily <nad@python.org>2018-10-20 04:37:51 (GMT)
commit60c663c0f76c790afbed4d673c3ce264dd226b8c (patch)
treeb2dc30410b3dc39c80e0e168ce44fac7a9a88b0b
parent03ca8b5f23e9fe122bb0ca80397a2481c10cd7c4 (diff)
downloadcpython-60c663c0f76c790afbed4d673c3ce264dd226b8c.zip
cpython-60c663c0f76c790afbed4d673c3ce264dd226b8c.tar.gz
cpython-60c663c0f76c790afbed4d673c3ce264dd226b8c.tar.bz2
bpo-34970: Protect tasks weak set manipulation in asyncio.all_tasks() (GH-9837) (GH-9849)
https://bugs.python.org/issue34970 (cherry picked from commit 97cf0828727ac2a269c89c5aa09570a69a22c83c) Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
-rw-r--r--Lib/asyncio/tasks.py8
-rw-r--r--Misc/NEWS.d/next/Library/2018-10-13-11-14-13.bpo-34970.SrJTY7.rst1
2 files changed, 7 insertions, 2 deletions
diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py
index 72792a2..416c346 100644
--- a/Lib/asyncio/tasks.py
+++ b/Lib/asyncio/tasks.py
@@ -35,7 +35,9 @@ def all_tasks(loop=None):
"""Return a set of all tasks for the loop."""
if loop is None:
loop = events.get_running_loop()
- return {t for t in _all_tasks
+ # NB: set(_all_tasks) is required to protect
+ # from https://bugs.python.org/issue34970 bug
+ return {t for t in list(_all_tasks)
if futures._get_loop(t) is loop and not t.done()}
@@ -45,7 +47,9 @@ def _all_tasks_compat(loop=None):
# method.
if loop is None:
loop = events.get_event_loop()
- return {t for t in _all_tasks if futures._get_loop(t) is loop}
+ # NB: set(_all_tasks) is required to protect
+ # from https://bugs.python.org/issue34970 bug
+ return {t for t in list(_all_tasks) if futures._get_loop(t) is loop}
class Task(futures._PyFuture): # Inherit Python Task implementation
diff --git a/Misc/NEWS.d/next/Library/2018-10-13-11-14-13.bpo-34970.SrJTY7.rst b/Misc/NEWS.d/next/Library/2018-10-13-11-14-13.bpo-34970.SrJTY7.rst
new file mode 100644
index 0000000..a58b3dd
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-10-13-11-14-13.bpo-34970.SrJTY7.rst
@@ -0,0 +1 @@
+Protect tasks weak set manipulation in ``asyncio.all_tasks()``