Welcome! Log In Create A New Profile

Advanced

[nginx] Fixed runtime handling of systems without EPOLLRDHUP support.

Sergey Kandaurov
May 30, 2022 06:14AM
details: https://hg.nginx.org/nginx/rev/5119c8150478
branches:
changeset: 8018:5119c8150478
user: Marcus Ball <marcus.ball@live.com>
date: Mon May 30 02:38:07 2022 +0300
description:
Fixed runtime handling of systems without EPOLLRDHUP support.

In 7583:efd71d49bde0 (nginx 1.17.5) along with introduction of the
ioctl(FIONREAD) support proper handling of systems without EPOLLRDHUP
support in the kernel (but with EPOLLRDHUP in headers) was broken.

Before the change, rev->available was never set to 0 unless
ngx_use_epoll_rdhup was also set (that is, runtime test for EPOLLRDHUP
introduced in 6536:f7849bfb6d21 succeeded). After the change,
rev->available might reach 0 on systems without runtime EPOLLRDHUP
support, stopping further reading in ngx_readv_chain() and ngx_unix_recv().
And, if EOF happened to be already reported along with the last event,
it is not reported again by epoll_wait(), leading to connection hangs
and timeouts on such systems.

This affects Linux kernels before 2.6.17 if nginx was compiled
with newer headers, and, more importantly, emulation layers, such as
DigitalOcean's App Platform's / gVisor's epoll emulation layer.

Fix is to explicitly check ngx_use_epoll_rdhup before the corresponding
rev->pending_eof tests in ngx_readv_chain() and ngx_unix_recv().

diffstat:

src/os/unix/ngx_readv_chain.c | 4 +++-
src/os/unix/ngx_recv.c | 4 +++-
2 files changed, 6 insertions(+), 2 deletions(-)

diffs (28 lines):

diff -r 6206bca52d73 -r 5119c8150478 src/os/unix/ngx_readv_chain.c
--- a/src/os/unix/ngx_readv_chain.c Mon May 30 02:37:59 2022 +0300
+++ b/src/os/unix/ngx_readv_chain.c Mon May 30 02:38:07 2022 +0300
@@ -55,7 +55,9 @@ ngx_readv_chain(ngx_connection_t *c, ngx

#if (NGX_HAVE_EPOLLRDHUP)

- if (ngx_event_flags & NGX_USE_EPOLL_EVENT) {
+ if ((ngx_event_flags & NGX_USE_EPOLL_EVENT)
+ && ngx_use_epoll_rdhup)
+ {
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
"readv: eof:%d, avail:%d",
rev->pending_eof, rev->available);
diff -r 6206bca52d73 -r 5119c8150478 src/os/unix/ngx_recv.c
--- a/src/os/unix/ngx_recv.c Mon May 30 02:37:59 2022 +0300
+++ b/src/os/unix/ngx_recv.c Mon May 30 02:38:07 2022 +0300
@@ -52,7 +52,9 @@ ngx_unix_recv(ngx_connection_t *c, u_cha

#if (NGX_HAVE_EPOLLRDHUP)

- if (ngx_event_flags & NGX_USE_EPOLL_EVENT) {
+ if ((ngx_event_flags & NGX_USE_EPOLL_EVENT)
+ && ngx_use_epoll_rdhup)
+ {
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
"recv: eof:%d, avail:%d",
rev->pending_eof, rev->available);
_______________________________________________
nginx-devel mailing list -- nginx-devel@nginx.org
To unsubscribe send an email to nginx-devel-leave@nginx.org
Subject Author Views Posted

[nginx] Fixed runtime handling of systems without EPOLLRDHUP support.

Sergey Kandaurov 134 May 30, 2022 06:14AM



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

Online Users

Guests: 59
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready