Welcome! Log In Create A New Profile

Advanced

[nginx] Upstream: use EPOLLRDHUP to check broken connections (ti...

Valentin Bartenev
September 16, 2013 10:36AM
details: http://hg.nginx.org/nginx/rev/46bdbca10dfc
branches:
changeset: 5373:46bdbca10dfc
user: Valentin Bartenev <vbart@nginx.com>
date: Mon Sep 16 18:33:39 2013 +0400
description:
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).

This allows to detect client connection close with pending data on Linux
while processing upstream.

diffstat:

src/http/ngx_http_upstream.c | 49 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 49 insertions(+), 0 deletions(-)

diffs (59 lines):

diff -r 36b58ddb566d -r 46bdbca10dfc src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c Fri Jul 12 14:51:07 2013 +0400
+++ b/src/http/ngx_http_upstream.c Mon Sep 16 18:33:39 2013 +0400
@@ -1070,6 +1070,55 @@ ngx_http_upstream_check_broken_connectio

#endif

+#if (NGX_HAVE_EPOLLRDHUP)
+
+ if ((ngx_event_flags & NGX_USE_EPOLL_EVENT) && ev->pending_eof) {
+ socklen_t len;
+
+ ev->eof = 1;
+ c->error = 1;
+
+ err = 0;
+ len = sizeof(ngx_err_t);
+
+ /*
+ * BSDs and Linux return 0 and set a pending error in err
+ * Solaris returns -1 and sets errno
+ */
+
+ if (getsockopt(c->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len)
+ == -1)
+ {
+ err = ngx_errno;
+ }
+
+ if (err) {
+ ev->error = 1;
+ }
+
+ if (!u->cacheable && u->peer.connection) {
+ ngx_log_error(NGX_LOG_INFO, ev->log, err,
+ "epoll_wait() reported that client prematurely closed "
+ "connection, so upstream connection is closed too");
+ ngx_http_upstream_finalize_request(r, u,
+ NGX_HTTP_CLIENT_CLOSED_REQUEST);
+ return;
+ }
+
+ ngx_log_error(NGX_LOG_INFO, ev->log, err,
+ "epoll_wait() reported that client prematurely closed "
+ "connection");
+
+ if (u->peer.connection == NULL) {
+ ngx_http_upstream_finalize_request(r, u,
+ NGX_HTTP_CLIENT_CLOSED_REQUEST);
+ }
+
+ return;
+ }
+
+#endif
+
n = recv(c->fd, buf, 1, MSG_PEEK);

err = ngx_socket_errno;

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Upstream: use EPOLLRDHUP to check broken connections (ti...

Valentin Bartenev 997 September 16, 2013 10:36AM



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

Online Users

Guests: 136
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