[nginx] svn commit: r5065 - in branches/stable-1.2: . src/http/modules
mdounin at mdounin.ru
mdounin at mdounin.ru
Mon Feb 11 16:11:18 UTC 2013
Author: mdounin
Date: 2013-02-11 16:11:14 +0000 (Mon, 11 Feb 2013)
New Revision: 5065
URL: http://trac.nginx.org/nginx/changeset/5065/nginx
Log:
Merge of r5027, r5028, r5029: fastcgi_keep_conn fixes.
*) FastCGI: fixed wrong connection close with fastcgi_keep_conn.
With fastcgi_keep_conn it was possible that connection was closed after
FCGI_STDERR record with zero padding and without any further data read
yet. This happended as f->state was set to ngx_http_fastcgi_st_padding
and then "break" happened, resulting in p->length being set to
f->padding, i.e. 0 (which in turn resulted in connection close).
Fix is to make sure we continue the loop after f->state is set.
*) FastCGI: unconditional state transitions. Checks for f->padding
before state transitions make code hard to follow, remove them and
make sure we always do another loop iteration after f->state is
set to ngx_http_fastcgi_st_padding.
*) FastCGI: proper handling of split fastcgi end request. If fastcgi
end request record was split between several network packets, with
fastcgi_keep_conn it was possible that connection was saved in
incorrect state (e.g. with padding bytes not yet read).
Modified:
branches/stable-1.2/
branches/stable-1.2/src/http/modules/ngx_http_fastcgi_module.c
Index: branches/stable-1.2
===================================================================
--- branches/stable-1.2 2013-02-11 16:09:35 UTC (rev 5064)
+++ branches/stable-1.2 2013-02-11 16:11:14 UTC (rev 5065)
Property changes on: branches/stable-1.2
___________________________________________________________________
Modified: svn:mergeinfo
## -1 +1 ##
-/trunk:4611-4632,4636-4657,4671-4672,4674-4676,4682,4684-4699,4704-4706,4713,4736-4741,4754,4756-4771,4775,4777-4780,4782-4785,4795,4811-4820,4822-4824,4828-4835,4840-4844,4865-4872,4885-4887,4890-4896,4913-4925,4933-4934,4939,4944-4949,4961-4969,4973-4974,4976-4994,4997,4999-5004,5011-5025,5030
+/trunk:4611-4632,4636-4657,4671-4672,4674-4676,4682,4684-4699,4704-4706,4713,4736-4741,4754,4756-4771,4775,4777-4780,4782-4785,4795,4811-4820,4822-4824,4828-4835,4840-4844,4865-4872,4885-4887,4890-4896,4913-4925,4933-4934,4939,4944-4949,4961-4969,4973-4974,4976-4994,4997,4999-5004,5011-5025,5027-5030
\ No newline at end of property
Modified: branches/stable-1.2/src/http/modules/ngx_http_fastcgi_module.c
===================================================================
--- branches/stable-1.2/src/http/modules/ngx_http_fastcgi_module.c 2013-02-11 16:09:35 UTC (rev 5064)
+++ branches/stable-1.2/src/http/modules/ngx_http_fastcgi_module.c 2013-02-11 16:11:14 UTC (rev 5065)
@@ -1356,11 +1356,7 @@
}
} else {
- if (f->padding) {
- f->state = ngx_http_fastcgi_st_padding;
- } else {
- f->state = ngx_http_fastcgi_st_version;
- }
+ f->state = ngx_http_fastcgi_st_padding;
}
continue;
@@ -1597,11 +1593,7 @@
f->length -= u->buffer.pos - start;
if (f->length == 0) {
- if (f->padding) {
- f->state = ngx_http_fastcgi_st_padding;
- } else {
- f->state = ngx_http_fastcgi_st_version;
- }
+ f->state = ngx_http_fastcgi_st_padding;
}
if (rc == NGX_HTTP_PARSE_HEADER_DONE) {
@@ -1696,13 +1688,8 @@
}
if (f->type == NGX_HTTP_FASTCGI_STDOUT && f->length == 0) {
+ f->state = ngx_http_fastcgi_st_padding;
- if (f->padding) {
- f->state = ngx_http_fastcgi_st_padding;
- } else {
- f->state = ngx_http_fastcgi_st_version;
- }
-
if (!flcf->keep_conn) {
p->upstream_done = 1;
}
@@ -1715,28 +1702,39 @@
if (f->type == NGX_HTTP_FASTCGI_END_REQUEST) {
- if (f->padding) {
- f->state = ngx_http_fastcgi_st_padding;
- } else {
- f->state = ngx_http_fastcgi_st_version;
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, p->log, 0,
+ "http fastcgi sent end request");
+
+ if (!flcf->keep_conn) {
+ p->upstream_done = 1;
+ break;
}
- p->upstream_done = 1;
+ continue;
+ }
+ }
- if (flcf->keep_conn) {
+
+ if (f->state == ngx_http_fastcgi_st_padding) {
+
+ if (f->type == NGX_HTTP_FASTCGI_END_REQUEST) {
+
+ if (f->pos + f->padding < f->last) {
+ p->upstream_done = 1;
+ break;
+ }
+
+ if (f->pos + f->padding == f->last) {
+ p->upstream_done = 1;
r->upstream->keepalive = 1;
+ break;
}
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, p->log, 0,
- "http fastcgi sent end request");
+ f->padding -= f->last - f->pos;
break;
}
- }
-
- if (f->state == ngx_http_fastcgi_st_padding) {
-
if (f->pos + f->padding < f->last) {
f->state = ngx_http_fastcgi_st_version;
f->pos += f->padding;
@@ -1788,22 +1786,28 @@
"FastCGI sent in stderr: \"%*s\"",
m + 1 - msg, msg);
- if (f->pos == f->last) {
- break;
- }
-
} else {
- if (f->padding) {
- f->state = ngx_http_fastcgi_st_padding;
- } else {
- f->state = ngx_http_fastcgi_st_version;
- }
+ f->state = ngx_http_fastcgi_st_padding;
}
continue;
}
+ if (f->type == NGX_HTTP_FASTCGI_END_REQUEST) {
+ if (f->pos + f->length <= f->last) {
+ f->state = ngx_http_fastcgi_st_padding;
+ f->pos += f->length;
+
+ continue;
+ }
+
+ f->length -= f->last - f->pos;
+
+ break;
+ }
+
+
/* f->type == NGX_HTTP_FASTCGI_STDOUT */
if (f->pos == f->last) {
@@ -1856,33 +1860,14 @@
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, p->log, 0,
"input buf #%d %p", b->num, b->pos);
- if (f->pos + f->length < f->last) {
-
- if (f->padding) {
- f->state = ngx_http_fastcgi_st_padding;
- } else {
- f->state = ngx_http_fastcgi_st_version;
- }
-
+ if (f->pos + f->length <= f->last) {
+ f->state = ngx_http_fastcgi_st_padding;
f->pos += f->length;
b->last = f->pos;
continue;
}
- if (f->pos + f->length == f->last) {
-
- if (f->padding) {
- f->state = ngx_http_fastcgi_st_padding;
- } else {
- f->state = ngx_http_fastcgi_st_version;
- }
-
- b->last = f->last;
-
- break;
- }
-
f->length -= f->last - f->pos;
b->last = f->last;
More information about the nginx-devel
mailing list