Describe the bug RedisModule_SignalKeyAsReady does not work as expected.

To reproduce

Here a minimal module that reproduces the issue:

#include "redismodule.h"
#include <stdlib.h>

int BlockedReplyCallback(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)  {
    RedisModule_Log(ctx, "warning", "Reply callback!");
    RedisModule_ReplyWithSimpleString(ctx, "We are done!");
    return REDISMODULE_OK;
}

int TimeoutReplyCallback(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)  {
    RedisModule_Log(ctx, "warning", "Timed out!");

    RedisModule_ReplyWithSimpleString(ctx, "Timed Out");
    return REDISMODULE_OK;
}


void BlockedFreePrivdata(RedisModuleCtx *ctx, void *privdata) {
    RedisModule_Log(ctx, "warning", "Freeing all priv data");
}

int HelloworldRand_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {

    RedisModuleBlockedClient* bc = RedisModule_BlockClientOnKeys(ctx, 
            BlockedReplyCallback, 
            TimeoutReplyCallback, 
            BlockedFreePrivdata,
            10000, 
            &argv[1],
            1, 
            NULL);

    RedisModule_SignalKeyAsReady(ctx, argv[1]);

    return REDISMODULE_OK;
}

int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
    if (RedisModule_Init(ctx,"helloworld",1,REDISMODULE_APIVER_1)
        == REDISMODULE_ERR) return REDISMODULE_ERR;

    if (RedisModule_CreateCommand(ctx,"bug1",
        HelloworldRand_RedisCommand, "",
        0, 0, 0) == REDISMODULE_ERR)
        return REDISMODULE_ERR;

    return REDISMODULE_OK;
}

Just load the module and run the command "bug1 123". It will be blocked until timing out after 10 seconds despite having called RedisModule_SignalKeyAsReady directly after blocking. Note, I also tested to calling RedisModule_SignalKeyAsReady from a timer callback with the exact same result.

Expected behavior

The BlockedReplyCallback should be called after signaling that the key is ready.

Additional information

This is on a Mac running redis 6.0.8 and the latest redismodule.h (from yesterday).

Comment From: manast

I did some test with redis-cli and I noticed that if the key that you listen to exists before calling the command, then it the reply callback is called, so it seems that the bug happens when the key does not exist at the time of blocking.

Comment From: guybe7

hello @manast what you described is actually not a bug, it's a misuse of the API: you're not supposed to "signal a key as ready" when the key doesn't exist (and thus, obviously not "ready")

Comment From: guybe7

may i know the reason you want to signal a non-existing key as ready? if it's a compelling enough we may consider to relax the definition of a "ready" key (i.e. now we assume a "ready" key must exist)

Comment From: manast

@guybe7 This was me trying to find all corner cases for SignalKeyAsReady, however the case that actually was a problem for me was this one (I have finally found a workaround using UnblockClient instead that works for my specific use case): https://github.com/redis/redis/issues/7880 so in other words, it makes sense that it does not work for non-existing keys but it would be probably good to have a one liner comment about this "limitation" even if it may be obvious for many.

Comment From: guybe7

@manast NP i will push a commit with updated docs/comments

Comment From: guybe7

closing