bpo-41891: ensure asyncio.wait_for waits for task completion (#22461)

diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py
index 0d3a24b..52f1e66 100644
--- a/Lib/asyncio/tasks.py
+++ b/Lib/asyncio/tasks.py
@@ -437,7 +437,10 @@ async def wait_for(fut, timeout):
                 return fut.result()
             else:
                 fut.remove_done_callback(cb)
-                fut.cancel()
+                # We must ensure that the task is not running
+                # after wait_for() returns.
+                # See https://bugs.python.org/issue32751
+                await _cancel_and_wait(fut, loop=loop)
                 raise
 
         if fut.done():