Welcome! Log In Create A New Profile

Advanced

[nginx] Upstream: avoid duplicate finalization.

Maxim Dounin
March 02, 2015 02:06PM
details: http://hg.nginx.org/nginx/rev/5abf5af257a7
branches:
changeset: 5994:5abf5af257a7
user: Maxim Dounin <mdounin@mdounin.ru>
date: Mon Mar 02 21:44:32 2015 +0300
description:
Upstream: avoid duplicate finalization.

A request may be already finalized when ngx_http_upstream_finalize_request()
is called, due to filter finalization: after filter finalization upstream
can be finalized via ngx_http_upstream_cleanup(), either from
ngx_http_terminate_request(), or because a new request was initiated
to an upstream. Then the upstream code will see an error returned from
the filter chain and will call the ngx_http_upstream_finalize_request()
function again.

To prevent corruption of various upstream data in this situation, make sure
to do nothing but merely call ngx_http_finalize_request().

Prodded by Yichun Zhang, for details see the thread at
http://nginx.org/pipermail/nginx-devel/2015-February/006539.html.

diffstat:

src/http/ngx_http_upstream.c | 12 ++++++++----
1 files changed, 8 insertions(+), 4 deletions(-)

diffs (22 lines):

diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -3751,10 +3751,14 @@ ngx_http_upstream_finalize_request(ngx_h
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"finalize http upstream request: %i", rc);

- if (u->cleanup) {
- *u->cleanup = NULL;
- u->cleanup = NULL;
- }
+ if (u->cleanup == NULL) {
+ /* the request was already finalized */
+ ngx_http_finalize_request(r, NGX_DONE);
+ return;
+ }
+
+ *u->cleanup = NULL;
+ u->cleanup = NULL;

if (u->resolved && u->resolved->ctx) {
ngx_resolve_name_done(u->resolved->ctx);

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Upstream: avoid duplicate finalization.

Maxim Dounin 658 March 02, 2015 02:06PM



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

Online Users

Guests: 250
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