Welcome! Log In Create A New Profile


Re: [PATCH] Introduced worker_shutdown_idle_delay

Artem Pogartsev via nginx-devel
November 08, 2023 12:00AM

Sending a patch in previous email, I fully understand that similar
proposals have already been discussed and rejected (those were
implemented in a different approach though):

Thus I understand that my patch might be rejected for similar reasons,
so I'll try to be specific and clarify what problems I'm trying to


While it's perfectly fine to close idle HTTP/1.1 connections at any
time according to RFC 9112, it can still cause unnecessary and
potentially avoidable problems during configuration reloads, such as:

- Retries for requests that are problematic for automatic retries
(non-idempotent requests). Unfortunately, it's not always possible to
make all requests idempotent and safe for automatic retries. As a
result, some of the closed idle connections will cause errors in client
applications that can only be resolved manually. This, in turn, leads
to a poor user experience.

- Unnecessary retries for all other types of requests. While the client
should be prepared for this, it will still result in additional latency
for retried requests that could be avoided (the more nginx reloads, the
more unnecessary retries).

- According to rfc9110 [1] it's not allowed to retry non-idempotent
requests by proxy. So it's not possible to retry them by some
intermediate proxy before nginx, and all those errors should be
returned to the client - this will lead to an additional latency even
if the client supports automatic retries for non-idempotent requests.

- According to rfc9110 [1] a client should not automatically retry a
failed automatic retry. There is a high probability that during nginx
reloads, a client will retry some requests via closing connections
because they all close simultaneously. This, again, will lead to a
portion of errors that can only be resolved manually.

The main idea: while clients should be prepared for unexpected errors
(such as server crashes, lack of free connections, etc.), there is no
point in deliberately creating such situations (especially in
environments with frequent nginx reloads). With properly configured

client_idle_timeout < min(server_shutdown_delay, server_idle_timeout)

this patch will allow to minimize the number of unnecessary retries and
errors for environments where it's critical.

Specifics of the environment:

- Nginx hosts as frontend L7 balancers for all incoming external L7
traffic in the datacenter, and in some cases for east-west traffic
between microservices.

- Almost all of http connections are keep-alive HTTP/1.1 with 300s

- Frequent nginx configuration reloads.

- Large amount of requests with non-idempotent methods.

- Large amount of long-lived "in-progress" connections such as
websockets (so in this situation there is no point to immediately
shutdown idle HTTP/1.1 connections, because old nginx workers will
continue to work anyway).

- High diversity of client applications (different mobile platforms,
different desktop platforms, different client libraries, different dev
teams for those client applications).

- We're currently using nginx-plus, so we can't just patch it, that's
why it's important for us to propagate this or a similar change in the
official release (we've also opened a ticket through the nginx-plus
support channel, in case it matters).

Additional comments:

This patch doesn't change the default behavior and tries to be as
unobtrusive as possible. With the option enabled, the configured
shutdown delay will only be applied to idle keepalive HTTP/1.1
connections - all other protocols will continue to work as usual (for
example, there is no point in delaying shutdown for HTTP/2 or HTTP/3
protocols - they have built-in graceful shutdown mechanisms). However,
if needed, the same behavior could easily be added for other protocols
in the future.

If you don't mind adding the proposed behavior, but don't like the way
it was done in the patch, then please advise how it could be reworked.

I also understand that additional tests should be added to the
nginx-tests repo. If you accept the patch, I will prepare the tests a
bit later.

Also, let me know if you need more details about use cases where this
patch might be useful.

[1] https://www.rfc-editor.org/rfc/rfc9110#section-9.2.2-7

Artem Pogartsev
nginx-devel mailing list
Subject Author Views Posted

[PATCH] Introduced worker_shutdown_idle_delay

Artem Pogartsev via nginx-devel 370 November 07, 2023 11:54PM

Re: [PATCH] Introduced worker_shutdown_idle_delay

Artem Pogartsev via nginx-devel 73 November 08, 2023 12:00AM

Re: [PATCH] Introduced worker_shutdown_idle_delay

Artem Pogartsev via nginx-devel 98 November 08, 2023 01:14AM

Re: [PATCH] Introduced worker_shutdown_idle_delay

Roman Arutyunyan 46 January 26, 2024 02:04AM

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

Online Users

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