• Oran Agra's avatar
    Fix busy loop in ae.c when timer event is about to fire (#8764) · 175a9e31
    Oran Agra authored
    The code used to decide on the next time to wake on a timer with
    microsecond accuracy, but when deciding to go to sleep it used
    milliseconds accuracy (with truncation), this means that it would wake
    up too early, see that there's no timer to process, and go to sleep
    again for 0ms again and again until the right microsecond arrived.
    
    i.e. a timer for 100ms, would sleep for 99ms, but then do a busy loop
    through the kernel in the last millisecond, triggering many calls to
    beforeSleep.
    
    The fix is to change all the logic in ae.c to work with microseconds,
    which is good since most of the ae backends support micro (or even nano)
    seconds. however the epoll backend, doesn't support micro, so to avoid
    this problem it needs to round upwards, rather than truncate.
    
    Issue created by the monotonic timer PR #7644 (redis 6.2)
    Before that, all the timers in ae.c were in milliseconds (using
    mstime), so when it requested the backend to sleep till the next timer
    event, it would have worked ok.
    175a9e31
ae.c 16.8 KB