Describe the bug
Issuing commands like:
XREAD BLOCK 2000 STREAMS mystream $
or
XREAD BLOCK 2000 STREAMS mystream <id_larger_than_latest>
will consistently time out if mystream is populated from within a module.
To reproduce Example of a module:
void insert_func(void *arg)
{
RedisModuleCtx *ctx = (RedisModuleCtx *)arg;
while(1) {
RedisModuleCallReply *rep = RedisModule_Call(ctx, "XADD", "ccclccc", "mystream", "MAXLEN", "~", 10, "*", "data", "some_value");
RedisModule_FreeCallReply(rep);
sleep(1);
}
}
int RedisModule_OnLoad(RedisModuleCtx *ctx, ...)
{
/* Init module */
...
pthread_t thread;
pthread_create(&thread, NULL, &insert_func, (void *)RedisModule_GetThreadSafeContext(ctx));
return REDISMODULE_OK;
}
Waiting for a new entry:
XREAD BLOCK 2000 STREAMS mystream $
(nil)
(2.01s)
Expected behavior XREAD returns the new entry.
Additional information
Data is inserted as expected.
Commands XRANGE and XREVRANGE give expected results.
Comment From: oranagra
@pelken just to be sure, the blocking XREAD isn't done by a module, just the XADD right? (running blocking commands from modules isn't currently supported https://github.com/redis/redis/pull/8025)
which version of redis are you using?
Comment From: pv-work
@oranagra Correct. Just XADD in the module. XREAD is tested in redis-cli or client app using hiredis lib.
redis version: 6.0.8
Comment From: oranagra
@pelken FYI, the module code you posted above violates thread safety, you need to use RM_ThreadSafeContextLock. but that's not what's causing the issue here.
is there any other traffic on redis? what's the hz config setting?
redis processes unblocked clients from beforeSleep which is executed from the main thread after serving commands, or waking up to do cron timer chores.
that's where your XREAD should have been unblocked (not immediately after calling XADD).
@guybe7 can you please take a look.
Comment From: pv-work
@pelken FYI, the module code you posted above violates thread safety, you need to use
RM_ThreadSafeContextLock. but that's not what's causing the issue here.Yes, I realize this. Opted to omit from example.
is there any other traffic on redis? what's the
hzconfig setting?
In my actual case there is quite a bit of traffic, data is added at a much higher rate to a number of streams. This is where I first noticed. But I have tested this small scale (1 stream, 1 insertion/second) with the same result. There are no other clients connected to redis.
hz is the default 10. I have tried setting it higher but it doesn't seem to help.
Comment From: guybe7
looking
Comment From: guybe7
fixed #7903 seems like it's not in the 6.0 branch...
Comment From: guybe7
forgot to git fetch... it is there, but was released in 6.0.9
@pelken can you re-test with 6.0.9?
Comment From: pv-work
@guybe7 yep 6.0.9 seems to have done the trick. Thanks for the help.
Comment From: guybe7
@pelken sure thing, please close the issue