• Meir Shpilraien (Spielrein)'s avatar
    Fix crash on RM_Call with script mode. (#10886) · 61baabd8
    Meir Shpilraien (Spielrein) authored
    The PR fixes 2 issues:
    
    ### RM_Call crash on script mode
    
    `RM_Call` can potentially be called from a background thread where `server.current_client`
    are not set. In such case we get a crash on `NULL` dereference.
    The fix is to check first if `server.current_client` is `NULL`, if it does we should
    verify disc errors and readonly replica as we do to any normal clients (no masters nor AOF).
    
    ### RM_Call block OOM commands when not needed
    
    Again `RM_Call` can be executed on a background thread using a `ThreadSafeCtx`.
    In such case `server.pre_command_oom_state` can be irrelevant and should not be
    considered when check OOM state. This cause OOM commands to be blocked when
    not necessarily needed.
    
    In such case, check the actual used memory (and not the cached value). Notice that in
    order to know if the cached value can be used, we check that the ctx that was used on
    the `RM_Call` is a ThreadSafeCtx. Module writer can potentially abuse the API and use
    ThreadSafeCtx on the main thread. We consider this as a API miss used.
    61baabd8
module.c 508 KB