pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: DaeMyung Kang <charsyam@gmail.com>
To: pgsql-hackers@lists.postgresql.org
Cc: DaeMyung Kang <charsyam@gmail.com>
Subject: [PATCH] Fix EINTR retry condition in pg_flush_data sync_file_range path.
Date: Thu, 30 Apr 2026 00:18:11 +0900
Message-ID: <20260429151811.1810874-1-charsyam@gmail.com> (raw)


Hi, Hackers,

While auditing src/backend/storage/file, I spotted a small but
unambiguous bug in pg_flush_data()'s sync_file_range() retry path.
Details below in the commit message; the fix is a one-token change.

Thanks,
DaeMyung

---

The retry branch compared the syscall return value (rc) against EINTR,
but sync_file_range() returns -1 on error and reports the actual errno
out-of-band, so rc == EINTR was always false and the retry was dead
code.  When sync_file_range() was actually interrupted by a signal,
control fell through to the warning/error path instead of retrying.

Compare errno instead, matching the convention already used elsewhere
in this file (e.g. the pg_pread/pg_pwrite EINTR retries) and a few
lines down for ENOSYS in this same block.
---
 src/backend/storage/file/fd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Attachments:

  [text/x-patch] 0001-Fix-EINTR-retry-condition-in-pg_flush_data-sync_file.patch (307B, ../20260429151811.1810874-1-charsyam@gmail.com/2-0001-Fix-EINTR-retry-condition-in-pg_flush_data-sync_file.patch)
  download | inline diff:
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index a8be066afe0..817855e2720 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -563,7 +563,7 @@ retry:
 		{
 			int			elevel;
 
-			if (rc == EINTR)
+			if (errno == EINTR)
 				goto retry;
 
 			/*

view thread (2+ messages)  latest in thread

Message-ID: <20260429151811.1810874-1-charsyam@gmail.com>
Permalink:  ../20260429151811.1810874-1-charsyam@gmail.com/
Also on:    postgresql.org/message-id/20260429151811.1810874-1-charsyam@gmail.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: charsyam@gmail.com, pgsql-hackers@lists.postgresql.org
  Subject: Re: [PATCH] Fix EINTR retry condition in pg_flush_data sync_file_range path.
  In-Reply-To: <20260429151811.1810874-1-charsyam@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox