List for cgit developers and users
 help / color / mirror / Atom feed
From: Filips R <>
Subject: Truncated output when writing to a pipe using sendfile
Date: Sat, 7 May 2022 15:49:23 +0300	[thread overview]
Message-ID: <> (raw)


I've been investigating an issue on my Alpine linux server running
cgit 1.2.3-r2.
When I call the CGI program and redirect to a regular file (or just
output to tty), the output is correct, however if the standard output
is a pipe, the output is truncated at 65523 bytes.

Here is the end of the diff between strace outputs:

 open("/var/cache/cgit/a1000000", O_RDONLY|O_LARGEFILE) = 3
 fstat(3, {st_mode=S_IFREG|0600, st_size=157003, ...}) = 0
 read(3, "st/tree/st.c\0Content-Type: text/"..., 4096) = 4096
-sendfile(1, 3, [13] => [157003], 156990) = 156990
+sendfile(1, 3, [13] => [65536], 156990) = 65523
 close(3)                                = 0
 exit_group(0)                           = ?
 +++ exited with 0 +++

I have managed to work around the issue by wrapping cgit and
redirecting to a temporary file.

Looks like the sendfile call comes from cache.c:95 -

senfile(2) says that a successful call may write fewer bytes than
requested; the caller should be prepared to retry the call if there
were unsent bytes

             reply	other threads:[~2022-05-07 12:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-07 12:49 Filips R [this message]
2022-05-07 13:03 ` Gianni Ceccarelli
2022-05-07 17:06   ` Hristo Venev
2022-05-07 17:07     ` [PATCH RESEND v2] cache: Tolerate short writes in print_slot Hristo Venev

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:

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

  git send-email \
    --in-reply-to='' \ \ \

* 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).