comparison src/http/ngx_http_upstream.c @ 6894:2204d71e88e5 stable-1.10

Upstream: fixed cache corruption and socket leaks with aio_write. The ngx_event_pipe() function wasn't called on write events with wev->delayed set. As a result, threaded writing results weren't properly collected in ngx_event_pipe_write_to_downstream() when a write event was triggered for a completed write. Further, this wasn't detected, as p->aio was reset by a thread completion handler, and results were later collected in ngx_event_pipe_read_upstream() instead of scheduling a new write of additional data. If this happened on the last reading from an upstream, last part of the response was never written to the cache file. Similar problems might also happen in case of timeouts when writing to client, as this also results in ngx_event_pipe() not being called on write events. In this scenario socket leaks were observed. Fix is to check if p->writing is set in ngx_event_pipe_read_upstream(), and therefore collect results of previous write operations in case of read events as well, similar to how we do so in ngx_event_pipe_write_downstream(). This is enough to fix the wev->delayed case. Additionally, we now call ngx_event_pipe() from ngx_http_upstream_process_request() if there are uncollected write operations (p->writing and !p->aio). This also fixes the wev->timedout case.
author Maxim Dounin <mdounin@mdounin.ru>
date Fri, 20 Jan 2017 21:14:19 +0300
parents 2cd019520210
children
comparison
equal deleted inserted replaced
6893:a3e6d660b179 6894:2204d71e88e5
3742 ngx_event_pipe_t *p; 3742 ngx_event_pipe_t *p;
3743 3743
3744 p = u->pipe; 3744 p = u->pipe;
3745 3745
3746 #if (NGX_THREADS) 3746 #if (NGX_THREADS)
3747
3748 if (p->writing && !p->aio) {
3749
3750 /*
3751 * make sure to call ngx_event_pipe()
3752 * if there is an incomplete aio write
3753 */
3754
3755 if (ngx_event_pipe(p, 1) == NGX_ABORT) {
3756 ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
3757 return;
3758 }
3759 }
3760
3747 if (p->writing) { 3761 if (p->writing) {
3748 return; 3762 return;
3749 } 3763 }
3764
3750 #endif 3765 #endif
3751 3766
3752 if (u->peer.connection) { 3767 if (u->peer.connection) {
3753 3768
3754 if (u->store) { 3769 if (u->store) {