aboutsummaryrefslogtreecommitdiff
path: root/src/http/ngx_http_file_cache.c
diff options
context:
space:
mode:
authorMaxim Dounin <mdounin@mdounin.ru>2024-01-29 10:31:37 +0300
committerMaxim Dounin <mdounin@mdounin.ru>2024-01-29 10:31:37 +0300
commitb794465178ecf48f13b37e4397145b05fd3fe6df (patch)
treef35d2c58a628ba0559ed04c9fcdf6c9097396bb3 /src/http/ngx_http_file_cache.c
parentcc4c3ee0a45ca3a2eeac2874e9199bf42560015c (diff)
downloadnginx-b794465178ecf48f13b37e4397145b05fd3fe6df.tar.gz
nginx-b794465178ecf48f13b37e4397145b05fd3fe6df.zip
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.
Diffstat (limited to 'src/http/ngx_http_file_cache.c')
-rw-r--r--src/http/ngx_http_file_cache.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/http/ngx_http_file_cache.c b/src/http/ngx_http_file_cache.c
index aa5fd1917..6c49dd42d 100644
--- a/src/http/ngx_http_file_cache.c
+++ b/src/http/ngx_http_file_cache.c
@@ -690,6 +690,8 @@ ngx_http_file_cache_aio_read(ngx_http_request_t *r, ngx_http_cache_t *c)
c->file.aio->data = r;
c->file.aio->handler = ngx_http_cache_aio_event_handler;
+ ngx_add_timer(&c->file.aio->event, 60000);
+
r->main->blocked++;
r->aio = 1;
@@ -737,6 +739,17 @@ ngx_http_cache_aio_event_handler(ngx_event_t *ev)
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
"http file cache aio: \"%V?%V\"", &r->uri, &r->args);
+ if (ev->timedout) {
+ ngx_log_error(NGX_LOG_ALERT, c->log, 0,
+ "aio operation took too long");
+ ev->timedout = 0;
+ return;
+ }
+
+ if (ev->timer_set) {
+ ngx_del_timer(ev);
+ }
+
r->main->blocked--;
r->aio = 0;
@@ -786,6 +799,8 @@ ngx_http_cache_thread_handler(ngx_thread_task_t *task, ngx_file_t *file)
return NGX_ERROR;
}
+ ngx_add_timer(&task->event, 60000);
+
r->main->blocked++;
r->aio = 1;
@@ -807,6 +822,17 @@ ngx_http_cache_thread_event_handler(ngx_event_t *ev)
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
"http file cache thread: \"%V?%V\"", &r->uri, &r->args);
+ if (ev->timedout) {
+ ngx_log_error(NGX_LOG_ALERT, c->log, 0,
+ "thread operation took too long");
+ ev->timedout = 0;
+ return;
+ }
+
+ if (ev->timer_set) {
+ ngx_del_timer(ev);
+ }
+
r->main->blocked--;
r->aio = 0;