Describe the bug

A short description of the bug.

1:S 13 Nov 2020 06:18:06.183 # == CRITICAL == This replica is sending an error to its master: 'MULTI calls can not be nested' after processing the command 'multi'

To reproduce

1、in redismodule, register mydel command and sub callback 2、delete a key in mydel command (del keya) . and the del cmd need propagateto replica. 3、step 2 delete action will trigger step 1 sub callback. in sub callback, a propagate command is executed (del keyb).

master will generate coomand:

multi    //generate by del keya in custom module command
multi    //generate by del keyb in subscribe callback
del keyb
exec     //generate by del keyb in subscribe callback
del keya
exec     //generate by del keya in custom module command

Reason when trigger sub callback ,a new RedisModuleContext will be generated. the "REDISMODULE_CTX_MULTI_EMITTED" in old ctx is lost.

Comment From: oranagra

@YiLinice which version of redis are you using? what do you mean by "sub callback"? how do you delete the key in mydel command (using RedisModule_DeleteKey or RedisModule_Call)?

i seem to remember something like that was recently fixed, i found 616b1cb7a (which was part of 6.0 RC3), maybe there was another later fix, @guybe7 do you remember?

Comment From: guybe7

I think that this is the scenario: 1. Module command does RM_Call to DEL, sending a key space notification 2. Some module is registered to notifications (maybe same module) and upon the notification calls RM_Call DEL on another key.

This will cause a nested multi because each step has its own context

It seems to me like we need some global int to count nesting level

Comment From: guybe7

Or maybe RM call should inherit the multi flag of the caller

Comment From: linyi-xq

@YiLinice which version of redis are you using? what do you mean by "sub callback"? how do you delete the key in mydel command (using RedisModule_DeleteKey or RedisModule_Call)?

i seem to remember something like that was recently fixed, i found 616b1cb (which was part of 6.0 RC3), maybe there was another later fix, @guybe7 do you remember?

@oranagra redis version: 6.0.4 sub callback : RedisModule_SubscribeToKeyspaceEvents(ctx, mask, sub_callback); I use RedisModule_Call to delete key.

Comment From: linyi-xq

I think that this is the scenario:

  1. Module command does RM_Call to DEL, sending a key space notification
  2. Some module is registered to notifications (maybe same module) and upon the notification calls RM_Call DEL on another key.

This will cause a nested multi because each step has its own context

It seems to me like we need some global int to count nesting level

yes. this is bug scenario.

Comment From: guybe7

for the record: i think setting CLIENT_MULTI on c in RM_Call (if replicate) should solve this issue but we need to write a test