comparison src/http/v2/ngx_http_v2.h @ 6891:749bcfdf097a stable-1.10

HTTP/2: fixed posted streams handling. A bug was introduced by 82efcedb310b that could lead to timing out of responses or segmentation fault, when accept_mutex was enabled. The output queue in HTTP/2 can contain frames from different streams. When the queue is sent, all related write handlers need to be called. In order to do so, the streams were added to the h2c->posted queue after handling sent frames. Then this queue was processed in ngx_http_v2_write_handler(). If accept_mutex is enabled, the event's "ready" flag is set but its handler is not called immediately. Instead, the event is added to the ngx_posted_events queue. At the same time in this queue can be events from upstream connections. Such events can result in sending output queue before ngx_http_v2_write_handler() is triggered. And at the time ngx_http_v2_write_handler() is called, the output queue can be already empty with some streams added to h2c->posted. But after 82efcedb310b, these streams weren't processed if all frames have already been sent and the output queue was empty. This might lead to a situation when a number of streams were get stuck in h2c->posted queue for a long time. Eventually these streams might get closed by the send timeout. In the worst case this might also lead to a segmentation fault, if already freed stream was left in the h2c->posted queue. This could happen if one of the streams was terminated but wasn't closed, due to the HEADERS frame or a partially sent DATA frame left in the output queue. If this happened the ngx_http_v2_filter_cleanup() handler removed the stream from the h2c->waiting or h2c->posted queue on termination stage, before the frame has been sent, and the stream was again added to the h2c->posted queue after the frame was sent. In order to fix all these problems and simplify the code, write events of fake stream connections are now added to ngx_posted_events instead of using a custom h2c->posted queue.
author Valentin Bartenev <vbart@nginx.com>
date Mon, 28 Nov 2016 20:58:14 +0300
parents 09cf90250844
children
comparison
equal deleted inserted replaced
6890:16487f9e6665 6891:749bcfdf097a
135 135
136 ngx_http_v2_node_t **streams_index; 136 ngx_http_v2_node_t **streams_index;
137 137
138 ngx_http_v2_out_frame_t *last_out; 138 ngx_http_v2_out_frame_t *last_out;
139 139
140 ngx_queue_t posted;
141 ngx_queue_t dependencies; 140 ngx_queue_t dependencies;
142 ngx_queue_t closed; 141 ngx_queue_t closed;
143 142
144 ngx_uint_t last_sid; 143 ngx_uint_t last_sid;
145 144
190 189
191 size_t header_limit; 190 size_t header_limit;
192 191
193 ngx_pool_t *pool; 192 ngx_pool_t *pool;
194 193
195 unsigned handled:1; 194 unsigned waiting:1;
196 unsigned blocked:1; 195 unsigned blocked:1;
197 unsigned exhausted:1; 196 unsigned exhausted:1;
198 unsigned in_closed:1; 197 unsigned in_closed:1;
199 unsigned out_closed:1; 198 unsigned out_closed:1;
200 unsigned rst_sent:1; 199 unsigned rst_sent:1;