List for cgit developers and users
 help / color / mirror / Atom feed
From: "Valdis Vītoliņš" <valdis.vitolins@odo.lv>
To: cgit@lists.zx2c4.com
Cc: Leah Neukirchen <leah@vuxu.org>
Subject: Re: cache: sendfile(2) usage results in short writes to pipes
Date: Thu, 22 Dec 2022 10:58:00 +0200	[thread overview]
Message-ID: <8839a585-09fd-f672-871c-5fe58e98f82c@odo.lv> (raw)
In-Reply-To: <87wn6opniu.fsf@vuxu.org>

Hi, Leah!

Do I understand you correctly that, when compiling and deploying cgit
according to https://git.zx2c4.com/cgit/tree/README

before compilation I should add in Makefile:
HAVE_LINUX_SENDFILE = 1

Thanks!
Valdis

> Hi,
> 
> in cache.c:print_slot, sendfile is called only once, but not checked
> for short writes.  These happen for example when serving cgit via
> fcgiwrap, which uses a pipe, so the write only writes 65k:
> 
> [pid 31211] openat(AT_FDCWD, "/var/cache/cgit/b9200000", O_RDONLY) = 4
> [pid 31211] fstat(4, {st_mode=S_IFREG|0600, st_size=19824215, ...}) = 0
> [pid 31211] read(4, "mirror/glibc/snapshot/glibc-3aae"..., 4096) = 4096
> [pid 31211] sendfile(1, 4, [77] => [65536], 19824138) = 65459
> [pid 31211] close(4 <unfinished ...>
> 
> This results in truncated cache responses, and therefore broken
> downloads from snapshots (larger than 65k).
> 
> I assume this is also the cause for the bug reported in
> <0ef89b1e-6543-e726-2cf0-b68e7167fabe@odo.lv>, I added the author to Cc:.
> 
> I recommend running sendfile in a loop until the whole file is sent.
> I also recommend detecting sendfile errors and falling back to the
> default read/write implementation, as there are some Linux filesystems
> where sendfile fails permanently.
> 
> Disabling HAVE_LINUX_SENDFILE on build serves as a workaround.
> 
> cu,

       reply	other threads:[~2022-12-22  8:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87wn6opniu.fsf@vuxu.org>
2022-12-22  8:58 ` Valdis Vītoliņš [this message]
2022-12-18 18:38 Leah Neukirchen
2022-12-19 15:17 ` Jason A. Donenfeld

Reply instructions:

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

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

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8839a585-09fd-f672-871c-5fe58e98f82c@odo.lv \
    --to=valdis.vitolins@odo.lv \
    --cc=cgit@lists.zx2c4.com \
    --cc=leah@vuxu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).