Welcome! Log In Create A New Profile

Advanced

[nginx] Fixed sendfile() limit handling on Linux.

Maxim Dounin
October 29, 2021 04:22PM
details: https://hg.nginx.org/nginx/rev/a2613fc1bce5
branches:
changeset: 7948:a2613fc1bce5
user: Maxim Dounin <mdounin@mdounin.ru>
date: Fri Oct 29 20:21:51 2021 +0300
description:
Fixed sendfile() limit handling on Linux.

On Linux starting with 2.6.16, sendfile() silently limits all operations
to MAX_RW_COUNT, defined as (INT_MAX & PAGE_MASK). This incorrectly
triggered the interrupt check, and resulted in 0-sized writev() on the
next loop iteration.

Fix is to make sure the limit is always checked, so we will return from
the loop if the limit is already reached even if number of bytes sent is
not exactly equal to the number of bytes we've tried to send.

diffstat:

src/os/unix/ngx_linux_sendfile_chain.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)

diffs (21 lines):

diff -r 51a260276425 -r a2613fc1bce5 src/os/unix/ngx_linux_sendfile_chain.c
--- a/src/os/unix/ngx_linux_sendfile_chain.c Fri Oct 29 20:21:48 2021 +0300
+++ b/src/os/unix/ngx_linux_sendfile_chain.c Fri Oct 29 20:21:51 2021 +0300
@@ -38,6 +38,9 @@ static void ngx_linux_sendfile_thread_ha
* On Linux up to 2.6.16 sendfile() does not allow to pass the count parameter
* more than 2G-1 bytes even on 64-bit platforms: it returns EINVAL,
* so we limit it to 2G-1 bytes.
+ *
+ * On Linux 2.6.16 and later, sendfile() silently limits the count parameter
+ * to 2G minus the page size, even on 64-bit platforms.
*/

#define NGX_SENDFILE_MAXSIZE 2147483647L
@@ -216,7 +219,6 @@ ngx_linux_sendfile_chain(ngx_connection_
*/

send = prev_send + sent;
- continue;
}

if (send >= limit || in == NULL) {
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Fixed sendfile() limit handling on Linux.

Maxim Dounin 330 October 29, 2021 04:22PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 207
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready