Upstream Keepalive connection close

I have Nginx server configured with couple of backend servers with
keepalive
connections enabled.

I am trying to understand what will be the Nginx’s behaviour in case the
connection is closed by an upstream server legitimately when Nginx is
trying
to send a new request exactly at the same time. In this race condition,
does
Nginx re-try the request internally or does it return an error code?

In case Nginx needs to be forced to retry, should I be using
proxy_next_upstream? My understanding is that this setting will make the
request re-tried on the next server in the upstream block. On the same
note,
how do I force the retry on the failed server first to avoid cache
misses.

Thanks,
Gopala

Posted at Nginx Forum:

Hello!

On Tue, Jan 06, 2015 at 06:06:18AM -0500, Gona wrote:

request re-tried on the next server in the upstream block. On the same note,
how do I force the retry on the failed server first to avoid cache misses.

As of now, nginx will only retry the request to the next server, if
any (as soon as “proxy_next_upstream” includes “error”, which is
the default).


Maxim D.
http://nginx.org/

Hi Maxim,

Thanks for the response.

So my understanding from this is - the race condition is possible and
when
it happens with one server in the upstream block or
“proxy_next_upstream”
set to OFF, Nginx will return back an error without retrying. Is this
right?

Thanks,
Gopala

Posted at Nginx Forum:

Hello!

On Thu, Jan 15, 2015 at 10:53:40AM -0500, Gona wrote:

So my understanding from this is - the race condition is possible and when
it happens with one server in the upstream block or “proxy_next_upstream”
set to OFF, Nginx will return back an error without retrying. Is this
right?

Yes, in theory this is possible.


Maxim D.
http://nginx.org/

Hi Maxim,

If possible I would like to use a keep-alive connection timeout less
than
that of the backend servers to avoid premature connection close by
backend
server. As mentioned before, I am trying to avoid other options like
rerouting using proxy_next_upstream or retrying by downstream client.

Is there a way to set a timeout on keep-alive connections to backend
servers? Or even force close or invalidate the connection cache from
code?

Thanks,
Gona

Posted at Nginx Forum:

Hello!

On Mon, Feb 23, 2015 at 07:27:25AM -0500, Gona wrote:

Hi Maxim,

If possible I would like to use a keep-alive connection timeout less than
that of the backend servers to avoid premature connection close by backend
server. As mentioned before, I am trying to avoid other options like
rerouting using proxy_next_upstream or retrying by downstream client.

Is there a way to set a timeout on keep-alive connections to backend
servers? Or even force close or invalidate the connection cache from code?

As of now, there is no such option. If the problem you are trying
to solve is practical, it would be mostly trivial to add one.


Maxim D.
http://nginx.org/