mirror of
https://github.com/nginx/nginx.git
synced 2026-04-21 06:08:45 -04:00
Sticky: fixed expiration of learned sessions after reload.
Some checks failed
buildbot / buildbot (push) Has been cancelled
Some checks failed
buildbot / buildbot (push) Has been cancelled
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.
This commit is contained in:
parent
0380586e69
commit
52cda2849c
1 changed files with 57 additions and 2 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue