comparison src/event/modules/ngx_eventport_module.c @ 6806:75dbab4ea930

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.
author Dmitry Volyntsev <xeioex@nginx.com>
date Mon, 21 Nov 2016 16:03:42 +0300
parents dc92298b1852
children a72886067bbb
comparison
equal deleted inserted replaced
6805:52bd8cc17f34 6806:75dbab4ea930
538 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, 538 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
539 "strange port_getn() events fd:%d ev:%04Xd", 539 "strange port_getn() events fd:%d ev:%04Xd",
540 (int) event_list[i].portev_object, revents); 540 (int) event_list[i].portev_object, revents);
541 } 541 }
542 542
543 if ((revents & (POLLERR|POLLHUP|POLLNVAL)) 543 if (revents & (POLLERR|POLLHUP|POLLNVAL)) {
544 && (revents & (POLLIN|POLLOUT)) == 0) 544
545 {
546 /* 545 /*
547 * if the error events were returned without POLLIN or POLLOUT, 546 * if the error events were returned, add POLLIN and POLLOUT
548 * then add these flags to handle the events at least in one 547 * to handle the events at least in one active handler
549 * active handler
550 */ 548 */
551 549
552 revents |= POLLIN|POLLOUT; 550 revents |= POLLIN|POLLOUT;
553 } 551 }
554 552