comparison src/http/ngx_http_upstream.c @ 4509:8e24fb8ee3e7 stable-1.0

Merge of r4470: Fix for proxy_store leaving temporary files for subrequests. Temporary files might not be removed if the "proxy_store" or "fastcgi_store" directives were used for subrequests (e.g. ssi includes) and client closed connection prematurely. Non-active subrequests are finalized out of the control of the upstream module when client closes a connection. As a result, the code to remove unfinished temporary files in ngx_http_upstream_process_request() wasn't executed. Fix is to move relevant code into ngx_http_upstream_finalize_request() which is called in all cases, either directly or via the cleanup handler.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 05 Mar 2012 12:33:06 +0000
parents e66122a62bde
children 50143b8fb95f
comparison
equal deleted inserted replaced
4508:9f663da02aa7 4509:8e24fb8ee3e7
2614 2614
2615 2615
2616 static void 2616 static void
2617 ngx_http_upstream_process_request(ngx_http_request_t *r) 2617 ngx_http_upstream_process_request(ngx_http_request_t *r)
2618 { 2618 {
2619 ngx_uint_t del;
2620 ngx_temp_file_t *tf; 2619 ngx_temp_file_t *tf;
2621 ngx_event_pipe_t *p; 2620 ngx_event_pipe_t *p;
2622 ngx_http_upstream_t *u; 2621 ngx_http_upstream_t *u;
2623 2622
2624 u = r->upstream; 2623 u = r->upstream;
2626 2625
2627 if (u->peer.connection) { 2626 if (u->peer.connection) {
2628 2627
2629 if (u->store) { 2628 if (u->store) {
2630 2629
2631 del = p->upstream_error;
2632
2633 tf = u->pipe->temp_file;
2634
2635 if (p->upstream_eof || p->upstream_done) { 2630 if (p->upstream_eof || p->upstream_done) {
2631
2632 tf = u->pipe->temp_file;
2636 2633
2637 if (u->headers_in.status_n == NGX_HTTP_OK 2634 if (u->headers_in.status_n == NGX_HTTP_OK
2638 && (u->headers_in.content_length_n == -1 2635 && (u->headers_in.content_length_n == -1
2639 || (u->headers_in.content_length_n == tf->offset))) 2636 || (u->headers_in.content_length_n == tf->offset)))
2640 { 2637 {
2641 ngx_http_upstream_store(r, u); 2638 ngx_http_upstream_store(r, u);
2642 2639 u->store = 0;
2643 } else {
2644 del = 1;
2645 }
2646 }
2647
2648 if (del && tf->file.fd != NGX_INVALID_FILE) {
2649
2650 if (ngx_delete_file(tf->file.name.data) == NGX_FILE_ERROR) {
2651
2652 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
2653 ngx_delete_file_n " \"%s\" failed",
2654 u->pipe->temp_file->file.name.data);
2655 } 2640 }
2656 } 2641 }
2657 } 2642 }
2658 2643
2659 #if (NGX_HTTP_CACHE) 2644 #if (NGX_HTTP_CACHE)
2990 2975
2991 if (u->pipe && u->pipe->temp_file) { 2976 if (u->pipe && u->pipe->temp_file) {
2992 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 2977 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2993 "http upstream temp fd: %d", 2978 "http upstream temp fd: %d",
2994 u->pipe->temp_file->file.fd); 2979 u->pipe->temp_file->file.fd);
2980 }
2981
2982 if (u->store && u->pipe && u->pipe->temp_file
2983 && u->pipe->temp_file->file.fd != NGX_INVALID_FILE)
2984 {
2985 if (ngx_delete_file(u->pipe->temp_file->file.name.data)
2986 == NGX_FILE_ERROR)
2987 {
2988 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
2989 ngx_delete_file_n " \"%s\" failed",
2990 u->pipe->temp_file->file.name.data);
2991 }
2995 } 2992 }
2996 2993
2997 #if (NGX_HTTP_CACHE) 2994 #if (NGX_HTTP_CACHE)
2998 2995
2999 if (r->cache) { 2996 if (r->cache) {