This commit is contained in:
Sahand Akbarzadeh 2026-06-26 12:12:23 +08:00 committed by GitHub
commit 72d49ef53b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 25 additions and 3 deletions

View file

@ -76,7 +76,7 @@ static ngx_atomic_t ngx_stat_waiting0;
ngx_atomic_t *ngx_stat_waiting = &ngx_stat_waiting0;
#endif
ngx_pid_t *ngx_active_workers_pids;
static ngx_command_t ngx_events_commands[] = {
@ -566,6 +566,7 @@ ngx_event_module_init(ngx_cycle_t *cycle)
+ cl; /* ngx_stat_waiting */
#endif
size += ngx_min(NGX_MAX_PROCESSES * sizeof(ngx_pid_t), cl);
shm.size = size;
ngx_str_set(&shm.name, "nginx_shared_zone");
@ -610,7 +611,10 @@ ngx_event_module_init(ngx_cycle_t *cycle)
ngx_stat_reading = (ngx_atomic_t *) (shared + 7 * cl);
ngx_stat_writing = (ngx_atomic_t *) (shared + 8 * cl);
ngx_stat_waiting = (ngx_atomic_t *) (shared + 9 * cl);
ngx_active_workers_pids = (ngx_pid_t *) (shared + 11 * cl);
#else
ngx_active_workers_pids = (ngx_pid_t *) (shared + 3 * cl);
#endif
return NGX_OK;

View file

@ -476,7 +476,7 @@ extern ngx_atomic_t *ngx_stat_writing;
extern ngx_atomic_t *ngx_stat_waiting;
#endif
extern ngx_pid_t *ngx_active_workers_pids;
#define NGX_UPDATE_TIME 1
#define NGX_POST_EVENTS 2

View file

@ -59,6 +59,8 @@ typedef struct {
size_t body_start;
off_t fs_size;
ngx_msec_t lock_time;
ngx_int_t updating_updater_process_slot;
ngx_pid_t updating_updater_process_pid;
} ngx_http_file_cache_node_t;

View file

@ -657,10 +657,24 @@ ngx_http_file_cache_read(ngx_http_request_t *r, ngx_http_cache_t *c)
ngx_shmtx_lock(&cache->shpool->mutex);
if (c->node->updating &&
ngx_active_workers_pids[c->node->updating_updater_process_slot]
!= c->node->updating_updater_process_pid) {
/*
if the active pid in the index is different from
the initiator, it means the original worker has
crashed. reset the updating flag so another worker
can handle the cache update.
*/
c->node->updating = 0;
}
if (c->node->updating) {
rc = NGX_HTTP_CACHE_UPDATING;
} else {
c->node->updating_updater_process_slot = ngx_process_slot;
c->node->updating_updater_process_pid = ngx_pid;
c->node->updating = 1;
c->updating = 1;
c->lock_time = c->node->lock_time;

View file

@ -205,6 +205,8 @@ ngx_spawn_process(ngx_cycle_t *cycle, ngx_spawn_proc_pt proc, void *data,
ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "start %s %P", name, pid);
ngx_active_workers_pids[s] = pid;
ngx_processes[s].pid = pid;
ngx_processes[s].exited = 0;