Mercurial > hg > nginx
comparison src/http/ngx_http_file_cache.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 | f5515e727656 |
children | 0de20f43db25 |
comparison
equal
deleted
inserted
replaced
9201:791ead216b03 | 9202:e88cdaa0f1ff |
---|---|
688 c->reading = 1; | 688 c->reading = 1; |
689 | 689 |
690 c->file.aio->data = r; | 690 c->file.aio->data = r; |
691 c->file.aio->handler = ngx_http_cache_aio_event_handler; | 691 c->file.aio->handler = ngx_http_cache_aio_event_handler; |
692 | 692 |
693 ngx_add_timer(&c->file.aio->event, 60000); | |
694 | |
693 r->main->blocked++; | 695 r->main->blocked++; |
694 r->aio = 1; | 696 r->aio = 1; |
695 | 697 |
696 return NGX_AGAIN; | 698 return NGX_AGAIN; |
697 } | 699 } |
734 | 736 |
735 ngx_http_set_log_request(c->log, r); | 737 ngx_http_set_log_request(c->log, r); |
736 | 738 |
737 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, | 739 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, |
738 "http file cache aio: \"%V?%V\"", &r->uri, &r->args); | 740 "http file cache aio: \"%V?%V\"", &r->uri, &r->args); |
741 | |
742 if (ev->timedout) { | |
743 ngx_log_error(NGX_LOG_ALERT, c->log, 0, | |
744 "aio operation took too long"); | |
745 ev->timedout = 0; | |
746 return; | |
747 } | |
748 | |
749 if (ev->timer_set) { | |
750 ngx_del_timer(ev); | |
751 } | |
739 | 752 |
740 r->main->blocked--; | 753 r->main->blocked--; |
741 r->aio = 0; | 754 r->aio = 0; |
742 | 755 |
743 r->write_event_handler(r); | 756 r->write_event_handler(r); |
784 | 797 |
785 if (ngx_thread_task_post(tp, task) != NGX_OK) { | 798 if (ngx_thread_task_post(tp, task) != NGX_OK) { |
786 return NGX_ERROR; | 799 return NGX_ERROR; |
787 } | 800 } |
788 | 801 |
802 ngx_add_timer(&task->event, 60000); | |
803 | |
789 r->main->blocked++; | 804 r->main->blocked++; |
790 r->aio = 1; | 805 r->aio = 1; |
791 | 806 |
792 return NGX_OK; | 807 return NGX_OK; |
793 } | 808 } |
804 | 819 |
805 ngx_http_set_log_request(c->log, r); | 820 ngx_http_set_log_request(c->log, r); |
806 | 821 |
807 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, | 822 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, |
808 "http file cache thread: \"%V?%V\"", &r->uri, &r->args); | 823 "http file cache thread: \"%V?%V\"", &r->uri, &r->args); |
824 | |
825 if (ev->timedout) { | |
826 ngx_log_error(NGX_LOG_ALERT, c->log, 0, | |
827 "thread operation took too long"); | |
828 ev->timedout = 0; | |
829 return; | |
830 } | |
831 | |
832 if (ev->timer_set) { | |
833 ngx_del_timer(ev); | |
834 } | |
809 | 835 |
810 r->main->blocked--; | 836 r->main->blocked--; |
811 r->aio = 0; | 837 r->aio = 0; |
812 | 838 |
813 r->write_event_handler(r); | 839 r->write_event_handler(r); |