comparison src/http/modules/ngx_http_log_module.c @ 5897:dff86e2246a5

Access log: cancel the flush timer on graceful shutdown. Previously, it could prevent a worker process from exiting for up to the configured flush timeout.
author Valentin Bartenev <vbart@nginx.com>
date Mon, 25 Aug 2014 13:41:31 +0400
parents e3016ee8dba3
children ac2a8e4d8f01
comparison
equal deleted inserted replaced
5896:3efdd7788bb0 5897:dff86e2246a5
742 742
743 743
744 static void 744 static void
745 ngx_http_log_flush_handler(ngx_event_t *ev) 745 ngx_http_log_flush_handler(ngx_event_t *ev)
746 { 746 {
747 ngx_open_file_t *file;
748 ngx_http_log_buf_t *buffer;
749
747 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ev->log, 0, 750 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ev->log, 0,
748 "http log buffer flush handler"); 751 "http log buffer flush handler");
749 752
750 ngx_http_log_flush(ev->data, ev->log); 753 if (ev->timedout) {
754 ngx_http_log_flush(ev->data, ev->log);
755 return;
756 }
757
758 /* cancel the flush timer for graceful shutdown */
759
760 file = ev->data;
761 buffer = file->data;
762
763 buffer->event = NULL;
751 } 764 }
752 765
753 766
754 static u_char * 767 static u_char *
755 ngx_http_log_copy_short(ngx_http_request_t *r, u_char *buf, 768 ngx_http_log_copy_short(ngx_http_request_t *r, u_char *buf,
1409 } 1422 }
1410 1423
1411 buffer->event->data = log->file; 1424 buffer->event->data = log->file;
1412 buffer->event->handler = ngx_http_log_flush_handler; 1425 buffer->event->handler = ngx_http_log_flush_handler;
1413 buffer->event->log = &cf->cycle->new_log; 1426 buffer->event->log = &cf->cycle->new_log;
1427 buffer->event->cancelable = 1;
1414 1428
1415 buffer->flush = flush; 1429 buffer->flush = flush;
1416 } 1430 }
1417 1431
1418 buffer->gzip = gzip; 1432 buffer->gzip = gzip;