From ceb2128219308229e49acbbb7cfd41e62cb0dabd Mon Sep 17 00:00:00 2001 From: Ayush Tiwari Date: Fri, 16 Oct 2026 11:08:00 +0000 Subject: [PATCH v1 1/2] aio: Set error_errno before error_ioh in I/O workers IoWorkerMain() set error_ioh before emitting the DEBUG4 "processing IO" message, but set error_errno only just before reopening the file. If an error was raised while emitting the message, e.g. out of memory or an error from emit_log_hook, the error handler completed the IO with a zero result. That fails Assert(error_errno != 0); without assertions, a read instead fails with a misleading "read only 0 of N bytes" error. Set error_errno before error_ioh. This is only reachable when DEBUG4 messages from I/O workers are logged. Backpatch-through: 18 --- src/backend/storage/aio/method_worker.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/backend/storage/aio/method_worker.c b/src/backend/storage/aio/method_worker.c index cf75b2816b7..c9e17bde358 100644 --- a/src/backend/storage/aio/method_worker.c +++ b/src/backend/storage/aio/method_worker.c @@ -880,6 +880,12 @@ IoWorkerMain(const void *startup_data, size_t startup_data_len) } ioh = &pgaio_ctl->io_handles[io_index]; + + /* + * Must be set before error_ioh. There's not really a good errno + * we can report here. + */ + error_errno = ENOENT; error_ioh = ioh; errcallback.arg = ioh; @@ -898,10 +904,7 @@ IoWorkerMain(const void *startup_data, size_t startup_data_len) * It's very unlikely, but possible, that reopen fails. E.g. due * to memory allocations failing or file permissions changing or * such. In that case we need to fail the IO. - * - * There's not really a good errno we can report here. */ - error_errno = ENOENT; pgaio_io_reopen(ioh); /* -- 2.43.0