aboutsummaryrefslogtreecommitdiff
path: root/src/event/modules/ngx_poll_module.c
diff options
context:
space:
mode:
authorDmitry Volyntsev <xeioex@nginx.com>2016-11-21 16:03:42 +0300
committerDmitry Volyntsev <xeioex@nginx.com>2016-11-21 16:03:42 +0300
commit433fdbf8b6f2e60acd510cbd6ac1e4f67b17d52d (patch)
treefc332fcca43a880a9acfe7cb5c0eed9034cbd213 /src/event/modules/ngx_poll_module.c
parent89f92b32430c1df2a25580d15f1b047cde8fb792 (diff)
downloadnginx-433fdbf8b6f2e60acd510cbd6ac1e4f67b17d52d.tar.gz
nginx-433fdbf8b6f2e60acd510cbd6ac1e4f67b17d52d.zip
Events: improved error event handling for UDP sockets.
Normally, the epoll module calls the read and write handlers depending on whether EPOLLIN and EPOLLOUT are reported by epoll_wait(). No error processing is done in the module, the handlers are expected to get an error when doing I/O. If an error event is reported without EPOLLIN and EPOLLOUT, the module set both EPOLLIN and EPOLLOUT to ensure the error event is handled at least in one active handler. This works well unless the error is delivered along with only one of EPOLLIN or EPOLLOUT, and the corresponding handler does not do any I/O. For example, it happened when getting EPOLLERR|EPOLLOUT from epoll_wait() upon receiving "ICMP port unreachable" while proxying UDP. As the write handler had nothing to send it was not able to detect and log an error, and did not switch to the next upstream. The fix is to unconditionally set EPOLLIN and EPOLLOUT in case of an error event. In the aforementioned case, this causes the read handler to be called which does recv() and detects an error. In addition to the epoll module, analogous changes were made in devpoll/eventport/poll.
Diffstat (limited to 'src/event/modules/ngx_poll_module.c')
-rw-r--r--src/event/modules/ngx_poll_module.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/event/modules/ngx_poll_module.c b/src/event/modules/ngx_poll_module.c
index 4370950c0..a2a7079d6 100644
--- a/src/event/modules/ngx_poll_module.c
+++ b/src/event/modules/ngx_poll_module.c
@@ -353,13 +353,11 @@ ngx_poll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, ngx_uint_t flags)
continue;
}
- if ((revents & (POLLERR|POLLHUP|POLLNVAL))
- && (revents & (POLLIN|POLLOUT)) == 0)
- {
+ if (revents & (POLLERR|POLLHUP|POLLNVAL)) {
+
/*
- * if the error events were returned without POLLIN or POLLOUT,
- * then add these flags to handle the events at least in one
- * active handler
+ * if the error events were returned, add POLLIN and POLLOUT
+ * to handle the events at least in one active handler
*/
revents |= POLLIN|POLLOUT;