• antirez's avatar
    Modules: don't crash when Lua calls a module blocking command. · 31404355
    antirez authored
    Lua scripting does not support calling blocking commands, however all
    the native Redis commands are flagged as "s" (no scripting flag), so
    this is not possible at all. With modules there is no such mechanism in
    order to flag a command as non callable by the Lua scripting engine,
    moreover we cannot trust the modules users from complying all the times:
    it is likely that modules will be released to have blocking commands
    without such commands being flagged correctly, even if we provide a way to
    signal this fact.
    
    This commit attempts to address the problem in a short term way, by
    detecting that a module is trying to block in the context of the Lua
    scripting engine client, and preventing to do this. The module will
    actually believe to block as usually, but what happens is that the Lua
    script receives an error immediately, and the background call is ignored
    by the Redis engine (if not for the cleanup callbacks, once it
    unblocks).
    
    Long term, the more likely solution, is to introduce a new call called
    RedisModule_GetClientFlags(), so that a command can detect if the caller
    is a Lua script, and return an error, or avoid blocking at all.
    
    Being the blocking API experimental right now, more work is needed in
    this regard in order to reach a level well blocking module commands and
    all the other Redis subsystems interact peacefully.
    
    Now the effect is like the following:
    
        127.0.0.1:6379> eval "redis.call('hello.block',1,5000)" 0
        (error) ERR Error running script (call to
        f_b5ba35ff97bc1ef23debc4d6e9fd802da187ed53): @user_script:1: ERR
        Blocking module command called from Lua script
    
    This commit fixes issue #4127 in the short term.
    31404355
module.c 151 KB