Mercurial > hg > nginx
comparison src/http/ngx_http_copy_filter_module.c @ 9202:e88cdaa0f1ff
AIO operations now add timers (ticket #2162).
Each AIO (thread IO) operation being run is now accompanied with 1-minute
timer. This timer prevents unexpected shutdown of the worker process while
an AIO operation is running, and logs an alert if the operation is running
for too long.
This fixes "open socket left" alerts during worker processes shutdown
due to pending AIO (or thread IO) operations while corresponding requests
have no timers. In particular, such errors were observed while reading
cache headers (ticket #2162), and with worker_shutdown_timeout.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 29 Jan 2024 10:31:37 +0300 |
parents | ec2e6893caaa |
children | 0de20f43db25 |
comparison
equal
deleted
inserted
replaced
9201:791ead216b03 | 9202:e88cdaa0f1ff |
---|---|
168 r = ctx->filter_ctx; | 168 r = ctx->filter_ctx; |
169 | 169 |
170 file->aio->data = r; | 170 file->aio->data = r; |
171 file->aio->handler = ngx_http_copy_aio_event_handler; | 171 file->aio->handler = ngx_http_copy_aio_event_handler; |
172 | 172 |
173 ngx_add_timer(&file->aio->event, 60000); | |
174 | |
173 r->main->blocked++; | 175 r->main->blocked++; |
174 r->aio = 1; | 176 r->aio = 1; |
175 ctx->aio = 1; | 177 ctx->aio = 1; |
176 } | 178 } |
177 | 179 |
189 | 191 |
190 ngx_http_set_log_request(c->log, r); | 192 ngx_http_set_log_request(c->log, r); |
191 | 193 |
192 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, | 194 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, |
193 "http aio: \"%V?%V\"", &r->uri, &r->args); | 195 "http aio: \"%V?%V\"", &r->uri, &r->args); |
196 | |
197 if (ev->timedout) { | |
198 ngx_log_error(NGX_LOG_ALERT, c->log, 0, | |
199 "aio operation took too long"); | |
200 ev->timedout = 0; | |
201 return; | |
202 } | |
203 | |
204 if (ev->timer_set) { | |
205 ngx_del_timer(ev); | |
206 } | |
194 | 207 |
195 r->main->blocked--; | 208 r->main->blocked--; |
196 r->aio = 0; | 209 r->aio = 0; |
197 | 210 |
198 r->write_event_handler(r); | 211 r->write_event_handler(r); |
262 | 275 |
263 if (ngx_thread_task_post(tp, task) != NGX_OK) { | 276 if (ngx_thread_task_post(tp, task) != NGX_OK) { |
264 return NGX_ERROR; | 277 return NGX_ERROR; |
265 } | 278 } |
266 | 279 |
280 ngx_add_timer(&task->event, 60000); | |
281 | |
267 r->main->blocked++; | 282 r->main->blocked++; |
268 r->aio = 1; | 283 r->aio = 1; |
269 | 284 |
270 ctx = ngx_http_get_module_ctx(r, ngx_http_copy_filter_module); | 285 ctx = ngx_http_get_module_ctx(r, ngx_http_copy_filter_module); |
271 ctx->aio = 1; | 286 ctx->aio = 1; |
285 | 300 |
286 ngx_http_set_log_request(c->log, r); | 301 ngx_http_set_log_request(c->log, r); |
287 | 302 |
288 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, | 303 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, |
289 "http thread: \"%V?%V\"", &r->uri, &r->args); | 304 "http thread: \"%V?%V\"", &r->uri, &r->args); |
305 | |
306 if (ev->timedout) { | |
307 ngx_log_error(NGX_LOG_ALERT, c->log, 0, | |
308 "thread operation took too long"); | |
309 ev->timedout = 0; | |
310 return; | |
311 } | |
312 | |
313 if (ev->timer_set) { | |
314 ngx_del_timer(ev); | |
315 } | |
290 | 316 |
291 r->main->blocked--; | 317 r->main->blocked--; |
292 r->aio = 0; | 318 r->aio = 0; |
293 | 319 |
294 #if (NGX_HTTP_V2) | 320 #if (NGX_HTTP_V2) |