Klaus Demo nginx / 36a0713
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. Roman Arutyunyan 3 years ago
2 changed file(s) with 8 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
255255 rev = c->read;
256256
257257 c->udp->buffer = &buf;
258
258259 rev->ready = 1;
260 rev->active = 0;
259261
260262 rev->handler(rev);
261263
264266 }
265267
266268 rev->ready = 0;
269 rev->active = 1;
267270
268271 goto next;
269272 }
342345 rev = c->read;
343346 wev = c->write;
344347
348 rev->active = 1;
345349 wev->ready = 1;
346350
347351 rev->log = log;
452456 ngx_memcpy(buf, b->pos, n);
453457
454458 c->udp->buffer = NULL;
459
455460 c->read->ready = 0;
461 c->read->active = 1;
456462
457463 return n;
458464 }
16661666
16671667 flags = src->read->eof ? NGX_CLOSE_EVENT : 0;
16681668
1669 if (!src->shared && ngx_handle_read_event(src->read, flags) != NGX_OK) {
1669 if (ngx_handle_read_event(src->read, flags) != NGX_OK) {
16701670 ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR);
16711671 return;
16721672 }
16731673
16741674 if (dst) {
1675 if (!dst->shared && ngx_handle_write_event(dst->write, 0) != NGX_OK) {
1675 if (ngx_handle_write_event(dst->write, 0) != NGX_OK) {
16761676 ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR);
16771677 return;
16781678 }