Welcome! Log In Create A New Profile

Advanced

keepalive and 5xx

Posted by Frank Liu 
Frank Liu
keepalive and 5xx
July 10, 2018 02:20AM
Does nginx automatically disconnect keepalive connection if 5xx response
code is generated?
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Maxim Dounin
Re: keepalive and 5xx
July 10, 2018 07:10PM
Hello!

On Mon, Jul 09, 2018 at 05:16:36PM -0700, Frank Liu wrote:

> Does nginx automatically disconnect keepalive connection if 5xx response
> code is generated?

Not really. Keepalive is automatically switched off when a
response with one of the following error codes is generated by
nginx itself:

- 400 Bad Request
- 413 Request Entity Too Large
- 414 Request URI Too Large
- 500 Internal Server Error
- 501 Not Implemented

This is because such errors indicate that we might not be able
to maintain protocol state properly, and hence we need to close
the connection.

Details can be found in the ngx_http_special_response_handler()
function, see here:

http://hg.nginx.org/nginx/file/tip/src/http/ngx_http_special_response.c#l428

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Frank Liu
Re: keepalive and 5xx
July 11, 2018 02:10AM
Hi Maxim,

When you say "Keepalive is automatically switched off...", do you mean
nginx will send "Connection: close" as part of the response? What happens
if client doesn't honor that, and keeps sending another request to the
existing connection?

You also mentioned "error codes is generated by nginx itself", so what
happens if nginx is used as reverse proxy, and the error code is coming
from upstream? Will nginx switch off keepalive with client too?

Thanks!
Frank


On Tue, Jul 10, 2018 at 10:04 AM, Maxim Dounin <[email protected]> wrote:

> Hello!
>
> On Mon, Jul 09, 2018 at 05:16:36PM -0700, Frank Liu wrote:
>
> > Does nginx automatically disconnect keepalive connection if 5xx response
> > code is generated?
>
> Not really. Keepalive is automatically switched off when a
> response with one of the following error codes is generated by
> nginx itself:
>
> - 400 Bad Request
> - 413 Request Entity Too Large
> - 414 Request URI Too Large
> - 500 Internal Server Error
> - 501 Not Implemented
>
> This is because such errors indicate that we might not be able
> to maintain protocol state properly, and hence we need to close
> the connection.
>
> Details can be found in the ngx_http_special_response_handler()
> function, see here:
>
> http://hg.nginx.org/nginx/file/tip/src/http/ngx_http_
> special_response.c#l428
>
> --
> Maxim Dounin
> http://mdounin.ru/
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Maxim Dounin
Re: keepalive and 5xx
July 11, 2018 05:40AM
Hello!

On Tue, Jul 10, 2018 at 04:59:43PM -0700, Frank Liu wrote:

> When you say "Keepalive is automatically switched off...", do you mean
> nginx will send "Connection: close" as part of the response? What happens
> if client doesn't honor that, and keeps sending another request to the
> existing connection?

This means that nginx will not use keepalive for a particular
connection. That is, it will send "Connection: close" and will
close the connection. If there are any additional requests in the
connection (either pipelined, or due client ignoring "Connection:
close" signal), the client will have to retransmit them. Much
like in any other case when keepalive is switched off.

> You also mentioned "error codes is generated by nginx itself", so what
> happens if nginx is used as reverse proxy, and the error code is coming
> from upstream? Will nginx switch off keepalive with client too?

No (and that's why I wrote "generated by nginx itself"). As long
as the code is in an upstream response, it is simply passed to the
client.

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Sorry, only registered users may post in this forum.

Click here to login