comparison src/event/ngx_event_pipe.c @ 6876:a5d1b1383dea

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 e4c1f5b32868
children afceb32f3a8a
comparison
equal deleted inserted replaced
6875:022ea0d17177 6876:a5d1b1383dea
111 if (p->upstream_eof || p->upstream_error || p->upstream_done) { 111 if (p->upstream_eof || p->upstream_error || p->upstream_done) {
112 return NGX_OK; 112 return NGX_OK;
113 } 113 }
114 114
115 #if (NGX_THREADS) 115 #if (NGX_THREADS)
116
116 if (p->aio) { 117 if (p->aio) {
117 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, p->log, 0, 118 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, p->log, 0,
118 "pipe read upstream: aio"); 119 "pipe read upstream: aio");
119 return NGX_AGAIN; 120 return NGX_AGAIN;
120 } 121 }
122
123 if (p->writing) {
124 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, p->log, 0,
125 "pipe read upstream: writing");
126
127 rc = ngx_event_pipe_write_chain_to_temp_file(p);
128
129 if (rc != NGX_OK) {
130 return rc;
131 }
132 }
133
121 #endif 134 #endif
122 135
123 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, 136 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0,
124 "pipe read upstream: %d", p->upstream->read->ready); 137 "pipe read upstream: %d", p->upstream->read->ready);
125 138