comparison src/http/ngx_http_upstream.c @ 5373:46bdbca10dfc

Upstream: use EPOLLRDHUP to check broken connections (ticket #320). This allows to detect client connection close with pending data on Linux while processing upstream.
author Valentin Bartenev <vbart@nginx.com>
date Mon, 16 Sep 2013 18:33:39 +0400
parents cd46297325bd
children f1caf7b8ae1d
comparison
equal deleted inserted replaced
5372:36b58ddb566d 5373:46bdbca10dfc
1068 return; 1068 return;
1069 } 1069 }
1070 1070
1071 #endif 1071 #endif
1072 1072
1073 #if (NGX_HAVE_EPOLLRDHUP)
1074
1075 if ((ngx_event_flags & NGX_USE_EPOLL_EVENT) && ev->pending_eof) {
1076 socklen_t len;
1077
1078 ev->eof = 1;
1079 c->error = 1;
1080
1081 err = 0;
1082 len = sizeof(ngx_err_t);
1083
1084 /*
1085 * BSDs and Linux return 0 and set a pending error in err
1086 * Solaris returns -1 and sets errno
1087 */
1088
1089 if (getsockopt(c->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len)
1090 == -1)
1091 {
1092 err = ngx_errno;
1093 }
1094
1095 if (err) {
1096 ev->error = 1;
1097 }
1098
1099 if (!u->cacheable && u->peer.connection) {
1100 ngx_log_error(NGX_LOG_INFO, ev->log, err,
1101 "epoll_wait() reported that client prematurely closed "
1102 "connection, so upstream connection is closed too");
1103 ngx_http_upstream_finalize_request(r, u,
1104 NGX_HTTP_CLIENT_CLOSED_REQUEST);
1105 return;
1106 }
1107
1108 ngx_log_error(NGX_LOG_INFO, ev->log, err,
1109 "epoll_wait() reported that client prematurely closed "
1110 "connection");
1111
1112 if (u->peer.connection == NULL) {
1113 ngx_http_upstream_finalize_request(r, u,
1114 NGX_HTTP_CLIENT_CLOSED_REQUEST);
1115 }
1116
1117 return;
1118 }
1119
1120 #endif
1121
1073 n = recv(c->fd, buf, 1, MSG_PEEK); 1122 n = recv(c->fd, buf, 1, MSG_PEEK);
1074 1123
1075 err = ngx_socket_errno; 1124 err = ngx_socket_errno;
1076 1125
1077 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ev->log, err, 1126 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ev->log, err,