• Nir Rattner's avatar
    Fix overflow calculation for next timer event (#12474) · 24187ed8
    Nir Rattner authored
    The `retval` variable is defined as an `int`, so with 4 bytes, it cannot properly represent
    microsecond values greater than the equivalent of about 35 minutes. 
    
    This bug shouldn't impact standard Redis behavior because Redis doesn't have timer
    events that are scheduled as far as 35 minutes out, but it may affect custom Redis modules
    which interact with the event timers via the RM_CreateTimer API.
    
    The impact is that `usUntilEarliestTimer` may return 0 for as long as `retval` is scaled to
    an overflowing value. While `usUntilEarliestTimer` continues to return `0`, `aeApiPoll`
    will have a zero timeout, and so Redis will use significantly more CPU iterating through
    its event loop without pause. For timers scheduled far enough into the future, Redis will
    cycle between ~35 minute periods of high CPU usage and ~35 minute periods of standard
    CPU usage.
    24187ed8
ae.c 17.3 KB