From 97a8f4ef85fcbdd3ac2fa758ece1c8c0489c87e9 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Mon, 30 Jun 2025 00:59:53 +0300 Subject: [PATCH] Handle unexpected EOF while doing an LFC read more gracefully There's a bug somewhere because this happens in python regression tests. We need to hunt that down, but in any case, let's not get stuck in an infinite loop if it happens. --- pgxn/neon/communicator_new.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pgxn/neon/communicator_new.c b/pgxn/neon/communicator_new.c index 51a3358bae..fa2fc092ee 100644 --- a/pgxn/neon/communicator_new.c +++ b/pgxn/neon/communicator_new.c @@ -662,6 +662,19 @@ retry: (errcode_for_file_access(), errmsg("could not read block %lu in local cache file: %m", cached_block))); + if (nbytes == 0) + { + /* + * FIXME: if the file was concurrently truncated, I guess + * this is expected. We should finish the read by calling + * bcomm_finish_cache_read(), and only throw the error if + * it reported success. + */ + ereport(ERROR, + (errcode_for_file_access(), + errmsg("could not read block %lu in local cache file (unexpected EOF)", + cached_block))); + } bytes_total += nbytes; } }