Welcome! Log In Create A New Profile

Advanced

Re: Keepalived Connections Reset after reloading the configuration (HUP Signal)

October 07, 2020 04:29AM
Hi,

I'm looking into the same issue; how to improve graceful shutdown when using keep-alive connections.

It seems nginx at some point had support for doing graceful shutdown (if i read the code correctly):
http://hg.nginx.org/nginx/rev/03f1133f24e8

But it was removed at a later stage:
http://hg.nginx.org/nginx/rev/5e6142609e48

The feature was removed due to negative impact on CPU usage, maybe the process could be handled in ngx_http_finalize_connection(ngx_http_request_t *r) ? That may be a better option as it should only trigger when ngx_terminate and ngx_quit flags are active:

diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
index 2a0528c6..0b8e05fa 100644
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -2735,6 +2735,15 @@ ngx_http_finalize_connection(ngx_http_request_t *r)
return;
}

+ if (ngx_terminate
+ || ngx_quit
+ && r->keepalive)
+ {
+ r->keepalive = 0;
+ ngx_http_close_request(r, 0);
+ return;
+ }
+
if (clcf->lingering_close == NGX_HTTP_LINGERING_ALWAYS
|| (clcf->lingering_close == NGX_HTTP_LINGERING_ON
&& (r->lingering_close


Does this seem something that could work ?


One other option could be to expand the function ngx_close_idle_connections(ngx_cycle_t *cycle) to check if the connection is using keepalive, if so, set keeplive to 0. I believe that would ensure that during graceful shutdown, an keepalive connection would be able to perform one request, then asked to close the connection:

diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c
index c082d0da..df90c4f1 100644
--- a/src/core/ngx_connection.c
+++ b/src/core/ngx_connection.c
@@ -1334,8 +1334,10 @@ ngx_close_idle_connections(ngx_cycle_t *cycle)
{
ngx_uint_t i;
ngx_connection_t *c;
+ ngx_http_request_t *r;

c = cycle->connections;
+ r = cycle->

for (i = 0; i < cycle->connection_n; i++) {

@@ -1345,6 +1347,11 @@ ngx_close_idle_connections(ngx_cycle_t *cycle)
c[i].close = 1;
c[i].read->handler(c[i].read);
}
+
+ if (r->keepalive) {
+ r->keepalive = 0;
+ }
+
}
}

I understand that the second example is not a fully working example.
Subject Author Posted

Keepalived Connections Reset after reloading the configuration (HUP Signal)

Jocelyn Mocquant May 13, 2011 07:24PM

Re: Keepalived Connections Reset after reloading the configuration (HUP Signal)

Maxim Dounin May 16, 2011 07:34AM

Re: Keepalived Connections Reset after reloading the configuration (HUP Signal)

Jocelyn Mocquant May 16, 2011 06:14PM

Re: Keepalived Connections Reset after reloading the configuration (HUP Signal)

darthhexx March 28, 2019 08:49PM

Re: Keepalived Connections Reset after reloading the configuration (HUP Signal)

zakirenish September 11, 2020 05:54PM

Re: Keepalived Connections Reset after reloading the configuration (HUP Signal)

tored October 07, 2020 04:29AM

Re: Keepalived Connections Reset after reloading the configuration (HUP Signal)

Maxim Dounin April 01, 2019 01:06PM

Re: Keepalived Connections Reset after reloading the configuration (HUP Signal)

Maxim Dounin October 07, 2020 09:56AM

Re: Keepalived Connections Reset after reloading the configuration (HUP Signal)

tored October 08, 2020 03:31AM

Re: Keepalived Connections Reset after reloading the configuration (HUP Signal)

Maxim Dounin October 12, 2020 04:16PM

Re: Keepalived Connections Reset after reloading the configuration (HUP Signal)

allenhe February 17, 2021 11:40PM

Re: Keepalived Connections Reset after reloading the configuration (HUP Signal)

allenhe February 18, 2021 03:14AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

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