aio: Fix crash potential for pg_aios views due to late state update pgaio_io_reclaim() reset the fields in PgAioHandle before updating the state to IDLE or incrementing the generation. For most things that's OK, but for pg_get_aios() it is not - if it copied the PgAioHandle while fields were being reset, we wouldn't detect that and could call pgaio_io_get_target_description() with ioh->target == PGAIO_TID_INVALID, leading to a crash.
Fix this issue by incrementing the generation and state earlier, before resetting. Also add an assertion to pgaio_io_get_target_description() for the target to be valid - that'd have made this case a bit easier to debug. While at it, add/update a few related assertions. Author: Alexander Lakhin <exclus...@gmail.com> Discussion: https://postgr.es/m/062daca9-dfad-4750-9da8-b13388301...@gmail.com Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/0d9114b7040d7503096e2897f4c856b17d461f6a Modified Files -------------- src/backend/storage/aio/aio.c | 21 +++++++++++++++------ src/backend/storage/aio/aio_target.c | 12 +++++++++--- 2 files changed, 24 insertions(+), 9 deletions(-)