Welcome! Log In Create A New Profile

Advanced

Re: [PATCH] Make ngx_http_upstream provide a way to expose errors after sending out the response header

agentzh
April 06, 2013 09:14PM
Hello!

Below attaches V3 of my patch to make ngx_http_upstream detect
truncated responses. Changes since V2 are as follows:

1. Use 502 to call ngx_http_upstream_finalize_request when data
truncation happens.
2. When the header is already sent and a special response error code
is specified in ngx_http_upstream_finalize_request, use NGX_ERROR
instead of 0 to finalize the request.

Thanks!
-agentzh

--- nginx-1.2.7/src/http/ngx_http_upstream.c 2013-02-11 06:39:49.000000000 -0800
+++ nginx-1.2.7-patched/src/http/ngx_http_upstream.c 2013-04-06
17:16:54.444520038 -0700
@@ -2399,7 +2399,7 @@ ngx_http_upstream_process_non_buffered_u

if (c->read->timedout) {
ngx_connection_error(c, NGX_ETIMEDOUT, "upstream timed out");
- ngx_http_upstream_finalize_request(r, u, 0);
+ ngx_http_upstream_finalize_request(r, u, NGX_HTTP_GATEWAY_TIME_OUT);
return;
}

@@ -2446,13 +2446,20 @@ ngx_http_upstream_process_non_buffered_r
if (u->busy_bufs == NULL) {

if (u->length == 0
- || upstream->read->eof
- || upstream->read->error)
+ || (upstream->read->eof
+ && u->length == -1
+ && u->pipe
+ && u->pipe->length == -1))
{
ngx_http_upstream_finalize_request(r, u, 0);
return;
}

+ if (upstream->read->eof || upstream->read->error) {
+ ngx_http_upstream_finalize_request(r, u,
NGX_HTTP_BAD_GATEWAY);
+ return;
+ }
+
b->pos = b->start;
b->last = b->start;
}
@@ -2720,7 +2727,9 @@ ngx_http_upstream_process_request(ngx_ht

#endif

- if (p->upstream_done || p->upstream_eof || p->upstream_error) {
+ if (p->upstream_done
+ || (p->upstream_eof && u->length == -1 && p->length == -1))
+ {
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http upstream exit: %p", p->out);
#if 0
@@ -2729,6 +2738,14 @@ ngx_http_upstream_process_request(ngx_ht
ngx_http_upstream_finalize_request(r, u, 0);
return;
}
+
+ if (p->upstream_eof || p->upstream_error) {
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+ "http upstream exit: %p", p->out);
+
+ ngx_http_upstream_finalize_request(r, u, NGX_HTTP_BAD_GATEWAY);
+ return;
+ }
}

if (p->downstream_error) {
@@ -3087,9 +3104,9 @@ ngx_http_upstream_finalize_request(ngx_h

if (u->header_sent
&& rc != NGX_HTTP_REQUEST_TIME_OUT
- && (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE))
+ && rc >= NGX_HTTP_SPECIAL_RESPONSE)
{
- rc = 0;
+ rc = NGX_ERROR;
}

if (rc == NGX_DECLINED) {
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH] Make ngx_http_upstream provide a way to expose errors after sending out the response header Attachments

agentzh 1308 September 10, 2012 01:04AM

Re: [PATCH] Make ngx_http_upstream provide a way to expose errors after sending out the response header

Maxim Dounin 582 September 10, 2012 06:36AM

Re: [PATCH] Make ngx_http_upstream provide a way to expose errors after sending out the response header

agentzh 585 September 10, 2012 02:24PM

Re: [PATCH] Make ngx_http_upstream provide a way to expose errors after sending out the response header

Maxim Dounin 521 September 10, 2012 08:24PM

Re: [PATCH] Make ngx_http_upstream provide a way to expose errors after sending out the response header Attachments

agentzh 414 April 05, 2013 09:40PM

Re: [PATCH] Make ngx_http_upstream provide a way to expose errors after sending out the response header Attachments

agentzh 475 April 06, 2013 09:14PM

Re: [PATCH] Make ngx_http_upstream provide a way to expose errors after sending out the response header Attachments

agentzh 504 April 07, 2013 07:26PM

Re: [PATCH] Make ngx_http_upstream provide a way to expose errors after sending out the response header

Maxim Dounin 494 April 07, 2013 08:24PM

Re: [PATCH] Make ngx_http_upstream provide a way to expose errors after sending out the response header

agentzh 418 April 08, 2013 03:06PM

Re: [PATCH] Make ngx_http_upstream provide a way to expose errors after sending out the response header

Maxim Dounin 436 April 08, 2013 06:38PM

Re: [PATCH] Make ngx_http_upstream provide a way to expose errors after sending out the response header

agentzh 407 April 08, 2013 07:14PM

Re: [PATCH] Make ngx_http_upstream provide a way to expose errors after sending out the response header

Maxim Dounin 447 April 08, 2013 08:32PM

Re: [PATCH] Make ngx_http_upstream provide a way to expose errors after sending out the response header

Maxim Dounin 520 July 25, 2013 12:18PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 132
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready