diff --git a/src/server/main_service.cc b/src/server/main_service.cc index b82b6bbf8e1d..afd774222ef6 100644 --- a/src/server/main_service.cc +++ b/src/server/main_service.cc @@ -634,6 +634,7 @@ void Service::DispatchCommand(CmdArgList args, facade::ConnectionContext* cntx) uint64_t start_usec = ProactorBase::GetMonotonicTimeNs(), end_usec; + DispatchMonitorIfNeeded(cid->opt_mask() & CO::ADMIN, dfly_cntx, args); // Create command transaction intrusive_ptr dist_trans; @@ -685,8 +686,6 @@ void Service::DispatchCommand(CmdArgList args, facade::ConnectionContext* cntx) dfly_cntx->reply_builder()->CloseConnection(); } - DispatchMonitorIfNeeded(cid->opt_mask() & CO::ADMIN, dfly_cntx, args); - end_usec = ProactorBase::GetMonotonicTimeNs(); request_latency_usec.IncBy(cmd_str, (end_usec - start_usec) / 1000); diff --git a/tests/dragonfly/connection_test.py b/tests/dragonfly/connection_test.py index 36ebcb109565..320214e6b1ad 100644 --- a/tests/dragonfly/connection_test.py +++ b/tests/dragonfly/connection_test.py @@ -4,14 +4,62 @@ import aioredis import async_timeout +async def run_monitor_eval(monitor, expected): + async with monitor as mon: + count = 0 + max = len(expected) + while count < max: + try: + async with async_timeout.timeout(1): + response = await mon.next_command() + if "select" not in response["command"].lower(): + cmd = expected[count] + if cmd not in response["command"]: + print(f"command {response['command']} != {cmd}") + return False + else: + count = count + 1 + except Exception as e: + print(f"failed to monitor: {e}") + return False + return True + +''' +Test issue https://github.com/dragonflydb/dragonfly/issues/756 +Monitor command do not return when we have lua script issue +''' +@pytest.mark.asyncio +async def test_monitor_command_lua(async_pool): + expected = ["EVAL return redis", "GET bar", "EVAL return redis", "SET foo2"] + + conn = aioredis.Redis(connection_pool=async_pool) + monitor = conn.monitor() + + cmd1 = aioredis.Redis(connection_pool=async_pool) + future = asyncio.create_task(run_monitor_eval(monitor=monitor, expected=expected)) + await asyncio.sleep(1) + try: + res = await cmd1.eval(r'return redis.call("GET", "bar")', 0) + assert False # we have a bug here, it will return an error + except Exception as e: + assert "script tried accessing undeclared key" in str(e) + try: + res = await cmd1.eval(r'return redis.call("SET", KEYS[1], ARGV[1])', 1, 'foo2', 'bar2') + except Exception as e: + print(f"EVAL error: {e}") + assert False + await asyncio.sleep(0.1) + await future + status = future.result() + assert status + + ''' Test the monitor command. Open connection which is used for monitoring Then send on other connection commands to dragonfly instance Make sure that we are getting the commands in the monitor context ''' - - @pytest.mark.asyncio async def test_monitor_command(async_pool): def generate(max): @@ -39,9 +87,8 @@ async def process_cmd(monitor, key, value): if "select" not in response["command"].lower(): success = verify_response(response, key, value) if not success: - print(f"failed to verfiy message {response} for {key}/{value}") + print(f"failed to verify message {response} for {key}/{value}") return False, f"failed on the verification of the message {response} at {key}: {value}" - #await asyncio.sleep(0.01) else: return True, None except asyncio.TimeoutError: