changeset 226:21f2ace7c936 NGINX_0_3_60

nginx 0.3.60 *) Bugfix: a worker process may got caught in an endless loop while an error redirection; bug appeared in 0.3.59.
author Igor Sysoev <http://sysoev.ru>
date Fri, 18 Aug 2006 00:00:00 +0400
parents d91e823fa629
children f554f17a0fb7
files CHANGES CHANGES.ru src/core/nginx.h src/http/ngx_http_core_module.c src/http/ngx_http_request.c src/http/ngx_http_special_response.c
diffstat 6 files changed, 30 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES	Wed Aug 16 00:00:00 2006 +0400
+++ b/CHANGES	Fri Aug 18 00:00:00 2006 +0400
@@ -1,4 +1,10 @@
 
+Changes with nginx 0.3.60                                        18 Aug 2006
+
+    *) Bugfix: a worker process may got caught in an endless loop while an 
+       error redirection; bug appeared in 0.3.59.
+
+
 Changes with nginx 0.3.59                                        16 Aug 2006
 
     *) Feature: now is possible to do several redirection using the 
--- a/CHANGES.ru	Wed Aug 16 00:00:00 2006 +0400
+++ b/CHANGES.ru	Fri Aug 18 00:00:00 2006 +0400
@@ -1,4 +1,10 @@
 
+Изменения в nginx 0.3.60                                          18.08.2006
+
+    *) Исправление: во время перенаправления ошибки рабочий процесс мог 
+       зациклиться; ошибка появилась в 0.3.59.
+
+
 Изменения в nginx 0.3.59                                          16.08.2006
 
     *) Добавление: теперь можно делать несколько перенаправлений через 
--- a/src/core/nginx.h	Wed Aug 16 00:00:00 2006 +0400
+++ b/src/core/nginx.h	Fri Aug 18 00:00:00 2006 +0400
@@ -8,7 +8,7 @@
 #define _NGINX_H_INCLUDED_
 
 
-#define NGINX_VER          "nginx/0.3.59"
+#define NGINX_VER          "nginx/0.3.60"
 
 #define NGINX_VAR          "NGINX"
 #define NGX_OLDPID_EXT     ".oldbin"
--- a/src/http/ngx_http_core_module.c	Wed Aug 16 00:00:00 2006 +0400
+++ b/src/http/ngx_http_core_module.c	Fri Aug 18 00:00:00 2006 +0400
@@ -507,7 +507,7 @@
     r->valid_location = 1;
     r->uri_changed = 1;
 
-    r->phase = (r == r->main) ? NGX_HTTP_POST_READ_PHASE:
+    r->phase = (!r->internal) ? NGX_HTTP_POST_READ_PHASE:
                                 NGX_HTTP_SERVER_REWRITE_PHASE;
     r->phase_handler = 0;
 
@@ -1324,6 +1324,15 @@
 {
     ngx_http_core_srv_conf_t  *cscf;
 
+    r->uri_changes--;
+
+    if (r->uri_changes == 0) {
+        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+                      "rewrite or internal redirection cycle");
+        ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
+        return NGX_DONE;
+    }
+
     r->uri = *uri;
 
     if (args) {
@@ -1338,7 +1347,8 @@
                    "internal redirect: \"%V?%V\"", uri, &r->args);
 
     if (ngx_http_set_exten(r) != NGX_OK) {
-        return NGX_HTTP_INTERNAL_SERVER_ERROR;
+        ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
+        return NGX_DONE;
     }
 
     /* clear the modules contexts */
@@ -1351,8 +1361,6 @@
 
     r->internal = 1;
 
-    r->uri_changes--;
-
     ngx_http_handler(r);
 
     return NGX_DONE;
--- a/src/http/ngx_http_request.c	Wed Aug 16 00:00:00 2006 +0400
+++ b/src/http/ngx_http_request.c	Fri Aug 18 00:00:00 2006 +0400
@@ -424,6 +424,9 @@
     r->headers_out.content_length_n = -1;
     r->headers_out.last_modified_time = -1;
 
+    r->uri_changes = NGX_HTTP_MAX_URI_CHANGES + 1;
+    r->subrequests = NGX_HTTP_MAX_SUBREQUESTS + 1;
+
     r->http_state = NGX_HTTP_READING_REQUEST_STATE;
 
     ctx = c->log->data;
@@ -667,9 +670,6 @@
                 c->write->handler = ngx_http_request_handler;
                 r->read_event_handler = ngx_http_block_read;
 
-                r->uri_changes = NGX_HTTP_MAX_URI_CHANGES + 1;
-                r->subrequests = NGX_HTTP_MAX_SUBREQUESTS + 1;
-
                 ngx_http_handler(r);
 
                 return;
--- a/src/http/ngx_http_special_response.c	Wed Aug 16 00:00:00 2006 +0400
+++ b/src/http/ngx_http_special_response.c	Fri Aug 18 00:00:00 2006 +0400
@@ -312,6 +312,7 @@
     }
 
     r->headers_out.status = error;
+    r->err_status = error;
 
     if (r->keepalive != 0) {
         switch (error) {
@@ -340,7 +341,7 @@
 
     clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
 
-    if (clcf->error_pages) {
+    if (r->uri_changes && clcf->error_pages) {
 
         err_page = clcf->error_pages->elts;