Skip to content

Commit 96da905

Browse files
committed
aio: Be more paranoid about interrupts
As reported by Noah, it's possible, although practically very unlikely, that interrupts could be processed in between pgaio_io_reopen() and pgaio_io_perform_synchronously(). Prevent that by explicitly holding interrupts. It also seems good to add an assertion to pgaio_io_before_prep() to ensure that interrupts are held, as otherwise FDs referenced by the IO could be closed during interrupt processing. All code in the aio series currently runs the code with interrupts held, but it seems better to be paranoid. Reviewed-by: Noah Misch <noah@leadboat.com> Reported-by: Noah Misch <noah@leadboat.com> Discussion: https://postgr.es/m/20250324002939.5c.nmisch@google.com
1 parent 47a1f07 commit 96da905

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/backend/storage/aio/aio_io.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ pgaio_io_before_prep(PgAioHandle *ioh)
159159
Assert(pgaio_my_backend->handed_out_io == ioh);
160160
Assert(pgaio_io_has_target(ioh));
161161
Assert(ioh->op == PGAIO_OP_INVALID);
162+
163+
/*
164+
* Otherwise the FDs referenced by the IO could be closed due to interrupt
165+
* processing.
166+
*/
167+
Assert(!INTERRUPTS_CAN_BE_PROCESSED());
162168
}
163169

164170
/*

src/backend/storage/aio/method_worker.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,13 @@ IoWorkerMain(const void *startup_data, size_t startup_data_len)
476476
"worker %d processing IO",
477477
MyIoWorkerId);
478478

479+
/*
480+
* Prevent interrupts between pgaio_io_reopen() and
481+
* pgaio_io_perform_synchronously() that otherwise could lead to
482+
* the FD getting closed in that window.
483+
*/
484+
HOLD_INTERRUPTS();
485+
479486
/*
480487
* It's very unlikely, but possible, that reopen fails. E.g. due
481488
* to memory allocations failing or file permissions changing or
@@ -502,6 +509,8 @@ IoWorkerMain(const void *startup_data, size_t startup_data_len)
502509
* ensure we don't accidentally fail.
503510
*/
504511
pgaio_io_perform_synchronously(ioh);
512+
513+
RESUME_INTERRUPTS();
505514
}
506515
else
507516
{

0 commit comments

Comments
 (0)