Welcome! Log In Create A New Profile


[nginx] Events: fixed expiration of timers in the past.

Maxim Dounin
March 25, 2021 06:46PM
details: https://hg.nginx.org/nginx/rev/2ed5d03c2d90
changeset: 7806:2ed5d03c2d90
user: Maxim Dounin <mdounin@mdounin.ru>
date: Fri Mar 26 01:44:59 2021 +0300
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


src/event/ngx_event.c | 4 +---
1 files changed, 1 insertions(+), 3 deletions(-)

diffs (14 lines):

diff -r ade8160120c1 -r 2ed5d03c2d90 src/event/ngx_event.c
--- a/src/event/ngx_event.c Fri Mar 26 01:44:57 2021 +0300
+++ b/src/event/ngx_event.c Fri Mar 26 01:44:59 2021 +0300
@@ -257,9 +257,7 @@ ngx_process_events_and_timers(ngx_cycle_

- if (delta) {
- ngx_event_expire_timers();
- }
+ ngx_event_expire_timers();

ngx_event_process_posted(cycle, &ngx_posted_events);
nginx-devel mailing list
Subject Author Views Posted

[nginx] Events: fixed expiration of timers in the past.

Maxim Dounin 62 March 25, 2021 06:46PM

Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 65
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready