Repository: redis/redis

Issue:
Issues with PostExecUnitJobs and AOF
# Intro

The main issue we have is that currently `call` is in charge of incr/decr of `server.in_nested_call` (soon to be `server.execution_nesting`) and that AOF calls to `proc` directly, and doesn't even call `afterCommand`.
The result is that while loading AOF, all the PEJs will be accumulated and will only be executed after the first non-AOF command

# Other issues
In addition to the above:
1. The is a difference between startup AOF and DEBUG LOADAOF: In the latter server.execution_nesting is 1 throughout the loading process, and in the former, it's 0. We need to see if it has any adverse effects.
2.  if we have MULTI/EXEC inside an AOF, PEJ will be executed after each command in the transaction (AOF calls `proc` but `execCommand` calls `call`, incrementing `execution_nesting` from 0 to 1 and then from 1 to 0 in `afterCommand`), breaking the contract of PEJs

# To do
* We need to define the desired behavior and to add more tests that handle PEJs, propagation, and AOF
* we need to decide if modules will be allowed to register PEJ from AOF loading, and from replicas.


Discussion:

Patch:
diff --git a/src/module.c b/src/module.c
index 5c7a0ce0b9e..7caec9a5280 100644
--- a/src/module.c
+++ b/src/module.c
@@ -8614,8 +8614,14 @@ void firePostExecutionUnitJobs(void) {
  * infinite loops by halting the execution could result in violation of the feature correctness
  * and so Redis will make no attempt to protect the module from infinite loops.
  *
- * 'free_pd' can be NULL and in such case will not be used. */
+ * 'free_pd' can be NULL and in such case will not be used.
+ *
+ * Return REDISMODULE_OK on success and REDISMODULE_ERR if was called while loading data from disk (AOF or RDB) or
+ * if the instance is a readonly replica. */
 int RM_AddPostNotificationJob(RedisModuleCtx *ctx, RedisModulePostNotificationJobFunc callback, void *privdata, void (*free_privdata)(void*)) {
+    if (server.loading|| (server.masterhost && server.repl_slave_ro)) {
+        return REDISMODULE_ERR;
+    }
     RedisModulePostExecUnitJob *job = zmalloc(sizeof(*job));
     job->module = ctx->module;
     job->callback = callback;