Welcome! Log In Create A New Profile

Advanced

Understanding "proxy_ignore_client_abort" functionality

September 02, 2014 12:57PM
Hi,
I'm trying to understand how "proxy_ignore_client_abort" should affect connection to upstream server once client closes the connection, since it seems to behave different than i'm expecting.

I'm using the proxy module, with buffering on and proxy_ignore_client_abort on as well (proxy_store off).
For boring and not related reasons, once i start a connection to the upstream server i don't want to abort it, even if the client aborted the connection.

However, even with "proxy_ignore_client_abort" on, once the client closes the connection i still see that the upstream connection is closed by nginx.

I've run the scenario with a debugger and i see why this happens. This is the flow:

1. At first, in "ngx_http_upstream_init_request", if "proxy_ignore_client_abort" is on, nginx will not check for FIN/RST from client:

//-------------------------------------------------------------------------------------------------
if (!u->store && !r->post_action && !u->conf->ignore_client_abort) {
r->read_event_handler = ngx_http_upstream_rd_check_broken_connection;
r->write_event_handler = ngx_http_upstream_wr_check_broken_connection;
}
//-------------------------------------------------------------------------------------------------

2. Later on, when reading the body from upstream and writing to downstream, if client closed the connection the flag "p->downstream_error" is set to 1.

3. And the part that surprised me - in "ngx_http_upstream_process_request", if "downstream_error" flag is set, we also close the connection to upstream, regardless of the "proxy_ignore_client_abort" config:

//-------------------------------------------------------------------------------------------------
if (p->downstream_error) {
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http upstream downstream error");

if (!u->cacheable && !u->store && u->peer.connection) {
ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
}
}
//-------------------------------------------------------------------------------------------------

I'd expect the "proxy_ignore_client_abort" flag to be checked in the "if" in #3 as well (=don't close upstream connection if the flag is true).

My first thought was that if the file should not be stored or cached - there is no reason to continue the connection to upstream, so that this is by design. However if that's the case then proxy_ignore_client_abort is redundant.

Can you please shed some light on this? is this a bug? is it the desired behavior? (if so, please explain the reason behind it).

I'm using Nginx ver 1.4.1 (though if i didn't miss anything it should be the same in the latest version).

My location config (simplified) is:

location ~ "^/fetch/(.*)" {
proxy_pass http://$1;
proxy_buffering on;
proxy_buffers 10 1024k;
proxy_ignore_client_abort on;
proxy_max_temp_file_size 0;
proxy_http_version 1.1;
}

Thanks in advance,
Shmulik B
Subject Author Posted

Understanding "proxy_ignore_client_abort" functionality

shmulik September 02, 2014 12:57PM

Re: Understanding "proxy_ignore_client_abort" functionality

Maxim Dounin September 02, 2014 03:44PM

Re: Understanding "proxy_ignore_client_abort" functionality

shmulik September 02, 2014 04:04PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

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