comparison src/stream/ngx_stream_proxy_module.c @ 7440:6d4bc025c5a7

Prevented scheduling events on a shared connection. A shared connection does not own its file descriptor, which means that ngx_handle_read_event/ngx_handle_write_event calls should do nothing for it. Currently the c->shared flag is checked in several places in the stream proxy module prior to calling these functions. However it was not done everywhere. Missing checks could lead to calling ngx_handle_read_event/ngx_handle_write_event on shared connections. The problem manifested itself when using proxy_upload_rate and resulted in either duplicate file descriptor error (e.g. with epoll) or incorrect further udp packet processing (e.g. with kqueue). The fix is to set and reset the event active flag in a way that prevents ngx_handle_read_event/ngx_handle_write_event from scheduling socket events.
author Roman Arutyunyan <arut@nginx.com>
date Mon, 14 Jan 2019 20:36:23 +0300
parents 860d3907da1c
children 8acaa1161783
comparison
equal deleted inserted replaced
7439:5efc23d83bc2 7440:6d4bc025c5a7
1665 return; 1665 return;
1666 } 1666 }
1667 1667
1668 flags = src->read->eof ? NGX_CLOSE_EVENT : 0; 1668 flags = src->read->eof ? NGX_CLOSE_EVENT : 0;
1669 1669
1670 if (!src->shared && ngx_handle_read_event(src->read, flags) != NGX_OK) { 1670 if (ngx_handle_read_event(src->read, flags) != NGX_OK) {
1671 ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); 1671 ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR);
1672 return; 1672 return;
1673 } 1673 }
1674 1674
1675 if (dst) { 1675 if (dst) {
1676 if (!dst->shared && ngx_handle_write_event(dst->write, 0) != NGX_OK) { 1676 if (ngx_handle_write_event(dst->write, 0) != NGX_OK) {
1677 ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); 1677 ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR);
1678 return; 1678 return;
1679 } 1679 }
1680 1680
1681 if (!c->read->delayed && !pc->read->delayed) { 1681 if (!c->read->delayed && !pc->read->delayed) {