Redis multiple replica fails with repeated command #HD5

I’m stuck on Stage #HD5. I’m doing this challenge in Go.

I was able to replicate the commands to multiple replicas locally, confirming the keys are set in the replicas.

However, when running the test, it failed and it looks like replica-1 received repeated commands from master.

Here are the test logs with debug:

[tester::#HD5] Running tests for Stage #HD5 (Replication - Multi Replica Command Propagation)
[tester::#HD5] $ ./your_program.sh --port 6379
[your_program] 2025/02/06 15:36:05 Redis listening on port: 6379
[tester::#HD5] [handshake] Creating replica: 1
[tester::#HD5] [handshake] replica-1: $ redis-cli PING
[tester::#HD5] [handshake] replica-1: Sent bytes: "*1\r\n$4\r\nPING\r\n"
[tester::#HD5] [handshake] replica-1: Received bytes: "+PONG\r\n"
[tester::#HD5] [handshake] replica-1: Received RESP simple string: "PONG"
[your_program] 2025/02/06 15:36:05 received command: PING, args: []
[tester::#HD5] [handshake] Received "PONG"
[tester::#HD5] [handshake] replica-1: > REPLCONF listening-port 6380
[tester::#HD5] [handshake] replica-1: Sent bytes: "*3\r\n$8\r\nREPLCONF\r\n$14\r\nlistening-port\r\n$4\r\n6380\r\n"
[your_program] 2025/02/06 15:36:05 received command: REPLCONF, args: [listening-port 6380]
[tester::#HD5] [handshake] replica-1: Received bytes: "+OK\r\n"
[tester::#HD5] [handshake] replica-1: Received RESP simple string: "OK"
[tester::#HD5] [handshake] Received "OK"
[tester::#HD5] [handshake] replica-1: > REPLCONF capa psync2
[tester::#HD5] [handshake] replica-1: Sent bytes: "*3\r\n$8\r\nREPLCONF\r\n$4\r\ncapa\r\n$6\r\npsync2\r\n"
[tester::#HD5] [handshake] replica-1: Received bytes: "+OK\r\n"
[tester::#HD5] [handshake] replica-1: Received RESP simple string: "OK"
[your_program] 2025/02/06 15:36:05 received command: REPLCONF, args: [capa psync2]
[tester::#HD5] [handshake] Received "OK"
[tester::#HD5] [handshake] replica-1: > PSYNC ? -1
[tester::#HD5] [handshake] replica-1: Sent bytes: "*3\r\n$5\r\nPSYNC\r\n$1\r\n?\r\n$2\r\n-1\r\n"
[your_program] 2025/02/06 15:36:05 received command: PSYNC, args: [? -1]
[tester::#HD5] [handshake] replica-1: Received bytes: "+FULLRESYNC 2ed54f4867a49aa99a486dbe73166f414244c843 0\r\n"
[tester::#HD5] [handshake] replica-1: Received RESP simple string: "FULLRESYNC 2ed54f4867a49aa99a486dbe73166f414244c843 0"
[tester::#HD5] [handshake] Received "FULLRESYNC 2ed54f4867a49aa99a486dbe73166f414244c843 0"
[tester::#HD5] [handshake] Reading RDB file...
[tester::#HD5] [handshake] replica-1: Received bytes: "$88\r\nREDIS0011\xfa\tredis-ver\x057.2.0\xfa\nredis-bits\xc0@\xfa\x05ctime\xc2m\b\xbce\xfa\bused-mem°\xc4\x10\x00\xfa\baof-base\xc0\x00\xff\xf0n;\xfe\xc0\xffZ\xa2"
[tester::#HD5] [handshake] Received RDB file
[tester::#HD5] Creating replica: 2
[tester::#HD5] [handshake] replica-2: $ redis-cli PING
[tester::#HD5] [handshake] replica-2: Sent bytes: "*1\r\n$4\r\nPING\r\n"
[your_program] 2025/02/06 15:36:05 received command: PING, args: []
[tester::#HD5] [handshake] replica-2: Received bytes: "+PONG\r\n"
[tester::#HD5] [handshake] replica-2: Received RESP simple string: "PONG"
[tester::#HD5] [handshake] Received "PONG"
[tester::#HD5] [handshake] replica-2: > REPLCONF listening-port 6381
[tester::#HD5] [handshake] replica-2: Sent bytes: "*3\r\n$8\r\nREPLCONF\r\n$14\r\nlistening-port\r\n$4\r\n6381\r\n"
[tester::#HD5] [handshake] replica-2: Received bytes: "+OK\r\n"
[tester::#HD5] [handshake] replica-2: Received RESP simple string: "OK"
[your_program] 2025/02/06 15:36:05 received command: REPLCONF, args: [listening-port 6381]
[tester::#HD5] [handshake] Received "OK"
[tester::#HD5] [handshake] replica-2: > REPLCONF capa psync2
[tester::#HD5] [handshake] replica-2: Sent bytes: "*3\r\n$8\r\nREPLCONF\r\n$4\r\ncapa\r\n$6\r\npsync2\r\n"
[your_program] 2025/02/06 15:36:05 received command: REPLCONF, args: [capa psync2]
[tester::#HD5] [handshake] replica-2: Received bytes: "+OK\r\n"
[tester::#HD5] [handshake] replica-2: Received RESP simple string: "OK"
[tester::#HD5] [handshake] Received "OK"
[tester::#HD5] [handshake] replica-2: > PSYNC ? -1
[tester::#HD5] [handshake] replica-2: Sent bytes: "*3\r\n$5\r\nPSYNC\r\n$1\r\n?\r\n$2\r\n-1\r\n"
[tester::#HD5] [handshake] replica-2: Received bytes: "+FULLRESYNC 2ed54f4867a49aa99a486dbe73166f414244c843 0\r\n"
[tester::#HD5] [handshake] replica-2: Received RESP simple string: "FULLRESYNC 2ed54f4867a49aa99a486dbe73166f414244c843 0"
[your_program] 2025/02/06 15:36:05 received command: PSYNC, args: [? -1]
[tester::#HD5] [handshake] Received "FULLRESYNC 2ed54f4867a49aa99a486dbe73166f414244c843 0"
[tester::#HD5] [handshake] Reading RDB file...
[tester::#HD5] [handshake] replica-2: Received bytes: "$88\r\nREDIS0011\xfa\tredis-ver\x057.2.0\xfa\nredis-bits\xc0@\xfa\x05ctime\xc2m\b\xbce\xfa\bused-mem°\xc4\x10\x00\xfa\baof-base\xc0\x00\xff\xf0n;\xfe\xc0\xffZ\xa2"
[tester::#HD5] [handshake] Received RDB file
[tester::#HD5] Creating replica: 3
[tester::#HD5] [handshake] replica-3: $ redis-cli PING
[tester::#HD5] [handshake] replica-3: Sent bytes: "*1\r\n$4\r\nPING\r\n"
[your_program] 2025/02/06 15:36:05 received command: PING, args: []
[tester::#HD5] [handshake] replica-3: Received bytes: "+PONG\r\n"
[tester::#HD5] [handshake] replica-3: Received RESP simple string: "PONG"
[tester::#HD5] [handshake] Received "PONG"
[tester::#HD5] [handshake] replica-3: > REPLCONF listening-port 6382
[tester::#HD5] [handshake] replica-3: Sent bytes: "*3\r\n$8\r\nREPLCONF\r\n$14\r\nlistening-port\r\n$4\r\n6382\r\n"
[tester::#HD5] [handshake] replica-3: Received bytes: "+OK\r\n"
[tester::#HD5] [handshake] replica-3: Received RESP simple string: "OK"
[your_program] 2025/02/06 15:36:05 received command: REPLCONF, args: [listening-port 6382]
[tester::#HD5] [handshake] Received "OK"
[tester::#HD5] [handshake] replica-3: > REPLCONF capa psync2
[tester::#HD5] [handshake] replica-3: Sent bytes: "*3\r\n$8\r\nREPLCONF\r\n$4\r\ncapa\r\n$6\r\npsync2\r\n"
[tester::#HD5] [handshake] replica-3: Received bytes: "+OK\r\n"
[tester::#HD5] [handshake] replica-3: Received RESP simple string: "OK"
[your_program] 2025/02/06 15:36:05 received command: REPLCONF, args: [capa psync2]
[tester::#HD5] [handshake] Received "OK"
[tester::#HD5] [handshake] replica-3: > PSYNC ? -1
[tester::#HD5] [handshake] replica-3: Sent bytes: "*3\r\n$5\r\nPSYNC\r\n$1\r\n?\r\n$2\r\n-1\r\n"
[tester::#HD5] [handshake] replica-3: Received bytes: "+FULLRESYNC 2ed54f4867a49aa99a486dbe73166f414244c843 0\r\n"
[tester::#HD5] [handshake] replica-3: Received RESP simple string: "FULLRESYNC 2ed54f4867a49aa99a486dbe73166f414244c843 0"
[tester::#HD5] [handshake] Received "FULLRESYNC 2ed54f4867a49aa99a486dbe73166f414244c843 0"
[tester::#HD5] [handshake] Reading RDB file...
[your_program] 2025/02/06 15:36:05 received command: PSYNC, args: [? -1]
[tester::#HD5] [handshake] replica-3: Received bytes: "$88\r\nREDIS0011\xfa\tredis-ver\x057.2.0\xfa\nredis-bits\xc0@\xfa\x05ctime\xc2m\b\xbce\xfa\bused-mem°\xc4\x10\x00\xfa\baof-base\xc0\x00\xff\xf0n;\xfe\xc0\xffZ\xa2"
[tester::#HD5] [handshake] Received RDB file
[tester::#HD5] [test] client: $ redis-cli SET foo 123
[tester::#HD5] [test] client: Sent bytes: "*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$3\r\n123\r\n"
[your_program] 2025/02/06 15:36:05 received command: SET, args: [foo 123]
[tester::#HD5] [test] client: Received bytes: "+OK\r\n"
[tester::#HD5] [test] client: Received RESP simple string: "OK"
[tester::#HD5] [test] Received "OK"
[tester::#HD5] [test] client: > SET bar 456
[tester::#HD5] [test] client: Sent bytes: "*3\r\n$3\r\nSET\r\n$3\r\nbar\r\n$3\r\n456\r\n"
[your_program] 2025/02/06 15:36:05 received command: SET, args: [bar 456]
[tester::#HD5] [test] client: Received bytes: "+OK\r\n"
[tester::#HD5] [test] client: Received RESP simple string: "OK"
[tester::#HD5] [test] Received "OK"
[tester::#HD5] [test] client: > SET baz 789
[tester::#HD5] [test] client: Sent bytes: "*3\r\n$3\r\nSET\r\n$3\r\nbaz\r\n$3\r\n789\r\n"
[tester::#HD5] [test] client: Received bytes: "+OK\r\n"
[tester::#HD5] [test] client: Received RESP simple string: "OK"
[your_program] 2025/02/06 15:36:05 received command: SET, args: [baz 789]
[tester::#HD5] [test] Received "OK"
[tester::#HD5] [test] Testing Replica: 1/3
[tester::#HD5] [test] replica-1: Expecting "SET foo 123" to be propagated
[tester::#HD5] [test] replica-1: Received bytes: "*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$3\r\n123\r\n"
[tester::#HD5] [test] replica-1: Received RESP array: ["SET", "foo", "123"]
[tester::#HD5] [test] Received ["SET", "foo", "123"]
[tester::#HD5] [test] replica-1: Expecting "SET bar 456" to be propagated
[tester::#HD5] [test] replica-1: Received bytes: "*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$3\r\n123\r\n"
[tester::#HD5] [test] replica-1: Received RESP array: ["SET", "foo", "123"]
[tester::#HD5] Expected argument #1 to be "bar", got "foo"
[tester::#HD5] Test failed
[tester::#HD5] Terminating program
[tester::#HD5] Program terminated successfully

Hi @antelope-775, I added some logs and noticed that each replica is being added twice to replConns:

The issue seems to stem from here:

Thanks for helping to debug! That makes sense now. I have forgotten there were 2 REPLCONN sent each time. In the single-replica stage I was storing just a single conn that was replaced by the same conn each time, so this problem didn’t occur until I changed it to a slice.

Thanks again for your time looking into this!

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.