summaryrefslogtreecommitdiffhomepage
path: root/src/http/modules
diff options
context:
space:
mode:
authorAleksei Bavshin <a.bavshin@nginx.com>2026-02-17 12:02:59 -0800
committerAleksei Bavshin <a.bavshin@f5.com>2026-03-09 11:08:30 -0600
commit52cda2849cbc17fe82bc006d1571e657a42dba24 (patch)
tree8c72e0dde8d4df92b18bff5d87b38ef550697878 /src/http/modules
parent0380586e69fc7b0b8aa7cea2329fef54f8ae69cb (diff)
downloadnginx-52cda2849cbc17fe82bc006d1571e657a42dba24.tar.gz
nginx-52cda2849cbc17fe82bc006d1571e657a42dba24.tar.bz2
Sticky: fixed expiration of learned sessions after reload.
Previously, the expiration timer for learned session was not started until a new session is created. This could lead to the sessions being active past the expiration time.
Diffstat (limited to 'src/http/modules')
-rw-r--r--src/http/modules/ngx_http_upstream_sticky_module.c59
1 files changed, 57 insertions, 2 deletions
diff --git a/src/http/modules/ngx_http_upstream_sticky_module.c b/src/http/modules/ngx_http_upstream_sticky_module.c
index 60a55502b..917f8f030 100644
--- a/src/http/modules/ngx_http_upstream_sticky_module.c
+++ b/src/http/modules/ngx_http_upstream_sticky_module.c
@@ -148,7 +148,6 @@ static ngx_msec_t ngx_http_upstream_sticky_sess_expire(
static ngx_int_t ngx_http_upstream_sticky_sess_init_zone(
ngx_shm_zone_t *shm_zone, void *data);
-
static void *ngx_http_upstream_sticky_create_conf(ngx_conf_t *cf);
static char *ngx_http_upstream_sticky(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
@@ -158,6 +157,8 @@ static char *ngx_http_upstream_sticky_learn(ngx_conf_t *cf,
ngx_http_upstream_sticky_srv_conf_t *stcf,
ngx_http_upstream_srv_conf_t *us);
+static ngx_int_t ngx_http_upstream_sticky_init_worker(ngx_cycle_t *cycle);
+
static u_char expires[] =
"; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=315360000";
@@ -206,7 +207,7 @@ ngx_http_upstream_sticky_module =
NULL, /* init master */
NULL, /* init module */
- NULL, /* init process */
+ ngx_http_upstream_sticky_init_worker, /* init process */
NULL, /* init thread */
NULL, /* exit thread */
@@ -1456,3 +1457,57 @@ ngx_http_upstream_sticky_learn(ngx_conf_t *cf,
return NGX_CONF_OK;
}
+
+
+static ngx_int_t
+ngx_http_upstream_sticky_init_worker(ngx_cycle_t *cycle)
+{
+ ngx_msec_t wait;
+ ngx_uint_t i;
+ ngx_http_upstream_srv_conf_t **uscfp;
+ ngx_http_upstream_main_conf_t *umcf;
+ ngx_http_upstream_sticky_sess_t *sess;
+ ngx_http_upstream_sticky_srv_conf_t *stcf;
+
+ if ((ngx_process != NGX_PROCESS_WORKER || ngx_worker != 0)
+ && ngx_process != NGX_PROCESS_SINGLE)
+ {
+ return NGX_OK;
+ }
+
+ umcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_upstream_module);
+
+ if (umcf == NULL) {
+ return NGX_OK;
+ }
+
+ uscfp = umcf->upstreams.elts;
+
+ for (i = 0; i < umcf->upstreams.nelts; i++) {
+
+ if (uscfp[i]->srv_conf == NULL) {
+ continue;
+ }
+
+ stcf = ngx_http_conf_upstream_srv_conf(uscfp[i],
+ ngx_http_upstream_sticky_module);
+
+ if (stcf == NULL || stcf->shm_zone == NULL) {
+ continue;
+ }
+
+ sess = stcf->shm_zone->data;
+
+ ngx_shmtx_lock(&sess->shpool->mutex);
+
+ wait = ngx_http_upstream_sticky_sess_expire(sess, 0);
+
+ ngx_shmtx_unlock(&sess->shpool->mutex);
+
+ if (wait > 0) {
+ ngx_add_timer(&sess->event, wait);
+ }
+ }
+
+ return NGX_OK;
+}