micropython/extmod
Damien George 514bf1a191 extmod/uasyncio: Fix race with cancelled task waiting on finished task.
This commit fixes a problem with a race between cancellation of task A and
completion of task B, when A waits on B.  If task B completes just before
task A is cancelled then the cancellation of A does not work.  Instead,
the CancelledError meant to cancel A gets passed through to B (that's
expected behaviour) but B handles it as a "Task exception wasn't retrieved"
scenario, printing out such a message (this is because finished tasks point
their "coro" attribute to themselves to indicate they are done, and
implement the throw() method, but that method inadvertently catches the
CancelledError).  The correct behaviour is for B to bounce that
CancelledError back out.

This bug is mainly seen when wait_for() is used, and in that context the
symptoms are:
- occurs when using wait_for(T, S), if the task T being waited on finishes
  at exactly the same time as the wait-for timeout S expires
- task T will have run to completion
- the "Task exception wasn't retrieved message" is printed with
  "<class 'CancelledError'>" as the error (ie no traceback)
- the wait_for(T, S) call never returns (it's never put back on the
  uasyncio run queue) and all tasks waiting on this are blocked forever
  from running
- uasyncio otherwise continues to function and other tasks continue to be
  scheduled as normal

The fix here reworks the "waiting" attribute of Task to be called "state"
and uses it to indicate whether a task is: running and not awaited on,
running and awaited on, finished and not awaited on, or finished and
awaited on.  This means the task does not need to point "coro" to itself to
indicate finished, and also allows removal of the throw() method.

A benefit of this is that "Task exception wasn't retrieved" messages can go
back to being able to print the name of the coroutine function.

Fixes issue #7386.

Signed-off-by: Damien George <damien@micropython.org>
2021-06-16 13:02:37 +10:00
..
axtls-include
btstack extmod/modbluetooth: Separate enabling of "client" from "central". 2021-02-19 17:53:43 +11:00
crypto-algorithms
lwip-include
nimble extmod/modbluetooth: Separate enabling of "client" from "central". 2021-02-19 17:53:43 +11:00
re1.5 extmod/re1.5: Check and report byte overflow errors in _compilecode. 2021-04-06 13:36:42 +10:00
uasyncio extmod/uasyncio: Fix race with cancelled task waiting on finished task. 2021-06-16 13:02:37 +10:00
uzlib
webrepl
extmod.cmake extmod/extmod.cmake: Add support to build btree module with CMake. 2021-04-09 13:33:26 +10:00
extmod.mk extmod: Disable -Wmissing-field-initializers for lfs2. 2020-10-22 11:47:36 +02:00
machine_i2c.c extmod/machine_i2c: Add init protocol method for generic I2C bindings. 2020-11-23 19:45:04 +11:00
machine_i2c.h extmod/machine_i2c: Add init protocol method for generic I2C bindings. 2020-11-23 19:45:04 +11:00
machine_mem.c extmod/machine_mem: Only allow integers in machine.memX subscript. 2020-11-13 11:13:37 +11:00
machine_mem.h
machine_pinbase.c
machine_pinbase.h
machine_pulse.c
machine_pulse.h
machine_signal.c
machine_signal.h
machine_spi.c extmod/machine_spi: Remove "id" arg in SoftSPI constructor. 2020-10-01 12:57:10 +10:00
machine_spi.h ports: Support legacy soft I2C/SPI construction via id=-1 arg. 2020-10-01 12:57:10 +10:00
misc.h
modbluetooth.c extmod/modbluetooth: Free temp arrays in gatts register services. 2021-03-16 13:55:45 +11:00
modbluetooth.h extmod/modbluetooth: Separate enabling of "client" from "central". 2021-02-19 17:53:43 +11:00
modbtree.c
modframebuf.c extmod/modframebuf: Change int to unsigned int in format methods args. 2021-01-29 23:57:10 +11:00
modlwip.c
modonewire.c extmod/modonewire: Use pin_od_high/pin_od_low instead of pin_write. 2021-01-29 23:57:10 +11:00
moduasyncio.c extmod/uasyncio: Fix race with cancelled task waiting on finished task. 2021-06-16 13:02:37 +10:00
modubinascii.c extmod/modubinascii: Update code, docs for hexlify now CPython has sep. 2020-12-14 14:35:29 +11:00
moducryptolib.c
moductypes.c extmod/moductypes: Fix size and offset calculation for ARRAY of FLOAT32. 2021-05-06 13:11:33 +10:00
moduhashlib.c extmod/moduhashlib: Put hash obj in final state after digest is called. 2021-05-26 21:44:46 +10:00
moduheapq.c
modujson.c
modurandom.c extmod/modurandom: Support an argument of bits=0 to getrandbits. 2021-05-30 17:05:56 +10:00
modure.c
moduselect.c extmod: Remove old comments used for auto-doc generation. 2021-05-06 12:27:31 +10:00
modussl_axtls.c extmod/modussl: Fix ussl read/recv/send/write errors when non-blocking. 2021-02-17 11:50:54 +11:00
modussl_mbedtls.c extmod/modussl: Fix ussl read/recv/send/write errors when non-blocking. 2021-02-17 11:50:54 +11:00
modutimeq.c
moduwebsocket.c
moduwebsocket.h
moduzlib.c
modwebrepl.c
mpbthci.c
mpbthci.h
network_cyw43.c
network_cyw43.h
uos_dupterm.c all: Rename mp_keyboard_interrupt to mp_sched_keyboard_interrupt. 2021-04-30 15:13:43 +10:00
utime_mphal.c extmod/utime_mphal: Add generic utime.time_ns() function. 2020-10-01 14:20:42 +10:00
utime_mphal.h extmod/utime_mphal: Add generic utime.time_ns() function. 2020-10-01 14:20:42 +10:00
vfs_blockdev.c
vfs_fat_diskio.c
vfs_fat_file.c
vfs_fat.c extmod: Remove old comments used for auto-doc generation. 2021-05-06 12:27:31 +10:00
vfs_fat.h
vfs_lfs.c py, extmod: Add explicit initializers for default values. 2020-10-22 11:47:36 +02:00
vfs_lfs.h
vfs_lfsx_file.c
vfs_lfsx.c extmod/vfs_lfs: Support mounting LFS filesystems in read-only mode. 2020-10-29 11:43:52 +11:00
vfs_posix_file.c extmod/vfs_posix_file: Allow closing an already closed file. 2021-02-11 22:54:41 +11:00
vfs_posix.c
vfs_posix.h
vfs_reader.c
vfs.c extmod/vfs: Check block 0 and 1 when auto-detecting littlefs. 2021-01-29 15:02:55 +11:00
vfs.h
virtpin.c
virtpin.h