From 44859a41ee63b52632f0726d7bf1e6ca1ce47f83 Mon Sep 17 00:00:00 2001 From: DarrenJiang13 Date: Wed, 10 Aug 2022 16:58:54 +0800 Subject: [PATCH] fix the client type in trackingInvalidateKey() (#11052) Fix bug with scripts ignoring client tracking NOLOOP and send an invalidation message anyway. --- src/tracking.c | 2 +- tests/unit/tracking.tcl | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/tracking.c b/src/tracking.c index 7dc0250688..c4b534a623 100644 --- a/src/tracking.c +++ b/src/tracking.c @@ -388,7 +388,7 @@ void trackingInvalidateKey(client *c, robj *keyobj, int bcast) { /* If the client enabled the NOLOOP mode, don't send notifications * about keys changed by the client itself. */ if (target->flags & CLIENT_TRACKING_NOLOOP && - target == c) + target == server.current_client) { continue; } diff --git a/tests/unit/tracking.tcl b/tests/unit/tracking.tcl index d4a84482ad..8d4fd8c894 100644 --- a/tests/unit/tracking.tcl +++ b/tests/unit/tracking.tcl @@ -208,6 +208,19 @@ start_server {tags {"tracking network"}} { assert {$res eq {key1}} } + test {Invalid keys should not be tracked for scripts in NOLOOP mode} { + $rd_sg CLIENT TRACKING off + $rd_sg CLIENT TRACKING on NOLOOP + $rd_sg HELLO 3 + $rd_sg SET key1 1 + assert_equal "1" [$rd_sg GET key1] + + # For write command in script, invalid key should not be tracked with NOLOOP flag + $rd_sg eval "return redis.call('set', 'key1', '2')" 1 key1 + assert_equal "2" [$rd_sg GET key1] + $rd_sg CLIENT TRACKING off + } + test {Tracking only occurs for scripts when a command calls a read-only command} { r CLIENT TRACKING off r CLIENT TRACKING on