comparison src/event/ngx_event.c @ 7806:2ed5d03c2d90

Events: fixed expiration of timers in the past. If, at the start of an event loop iteration, there are any timers in the past (including timers expiring now), the ngx_process_events() function is called with zero timeout, and returns immediately even if there are no events. But the following code only calls ngx_event_expire_timers() if time actually changed, so this results in nginx spinning in the event loop till current time changes. While such timers are not expected to appear under normal conditions, as all such timers should be removed on previous event loop iterations, they still can appear due to bugs, zero timeouts set in the configuration (if this is not explicitly handled by the code), or due to external time changes on systems without clock_gettime(CLOCK_MONOTONIC). Fix is to call ngx_event_expire_timers() unconditionally. Calling it on each event loop iteration is not expected to be significant from performance point of view, especially compared to a syscall in ngx_process_events().
author Maxim Dounin <mdounin@mdounin.ru>
date Fri, 26 Mar 2021 01:44:59 +0300
parents 9ca8fb98ef1c
children c860f0b7010c f1986657fc26
comparison
equal deleted inserted replaced
7805:ade8160120c1 7806:2ed5d03c2d90
255 255
256 if (ngx_accept_mutex_held) { 256 if (ngx_accept_mutex_held) {
257 ngx_shmtx_unlock(&ngx_accept_mutex); 257 ngx_shmtx_unlock(&ngx_accept_mutex);
258 } 258 }
259 259
260 if (delta) { 260 ngx_event_expire_timers();
261 ngx_event_expire_timers();
262 }
263 261
264 ngx_event_process_posted(cycle, &ngx_posted_events); 262 ngx_event_process_posted(cycle, &ngx_posted_events);
265 } 263 }
266 264
267 265