| From: | Yingying Chen <cyy9255(at)gmail(dot)com> |
|---|---|
| To: | Peter Eisentraut <peter(at)eisentraut(dot)org> |
| Cc: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Re: Fix handling of copy_file_range() return value |
| Date: | 2026-06-22 08:46:45 |
| Message-ID: | CAGGTb64P9VP3DHEjQ6DAPowrkqfJrwdp2rgc3mm7baiCHD0gtg@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Mon, Jun 22, 2026 at 3:20 PM Peter Eisentraut <peter(at)eisentraut(dot)org>
wrote:
> While checking return/error handling of file system calls, I found that
> the copy_file_range() call in pg_combinebackup has a potential problem.
> If copy_file_range() returns 0, which is a documented condition, then
> the loop never makes progress and could spin forever.
>
> The other uses of copy_file_range() in the tree are surrounded by
> different logic and don't appear to have this problem.
>
> My suggested fix is to make a return value of 0 an error. It most
> likely indicates that the source file has an unexpected size.
>
Hi, Peter,
Thanks for the patch. I agree wb==0 should be treated as an error, so the
fix direction looks good to me.
I have a small comment:
====
wb = copy_file_range(s->fd, &off, wfd, NULL, BLCKSZ - nwritten, 0);
if (wb < 0)
pg_fatal("error while copying file range from \"%s\" to
\"%s\": %m",
s->filename, output_filename);
else if (wb == 0)
pg_fatal("unexpected end of file while copying file range
from \"%s\" to \"%s\"",
s->filename, output_filename);
As copy_file_range copies from s->fd, should pg_fatal just s->filename in
the error message? In that case, input_filename is no longer used in
write_reconstructed_file(), then it might be removed from the argument list.
Regards,
Yingying Chen
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Andrés Taylor | 2026-06-22 08:49:01 | Re: Remove redundant DISTINCT when GROUP BY already guarantees uniqueness |
| Previous Message | Andres Taylor | 2026-06-22 08:44:22 | Re: Remove redundant DISTINCT when GROUP BY already guarantees uniqueness |