I’m stuck on Stage #HD5 (Replication - Multi Replica Command Propagation)
I can spawn multiple replicas on my machine, and write commands are correctly propagated to each. Something like
Terminal 1: ./your_program.sh
Terminal 2: ./your_program.sh --port 1234 --replicaof "localhost 6379"
Terminal 3: ./your_program.sh --port 1235 --replicaof "localhost 6379"
Terminal 4: redis-cli SET foo bar
Terminal 4: redis-cli -p 1234 GET foo
Terminal 4: redis-cli -p 1235 GET foo
does what it should.
When I run codecrafters test
, the test for this stage successfully launches a first replica, but when it attempts to launch a second replica it cannot complete the handshake.
Specifically, when the second replica sends a PING, the server does not respond.
The last part of the logs (showing successful creation of the first replica and the failure of the second) are:
...
[tester::#HD5] [handshake] replica-1: Received RESP simple string: "FULLRESYNC aILQSGgs02FpYqCScYHxaEc1UdGhwGl5p6DYEqFn 0"
[tester::#HD5] [handshake] Received "FULLRESYNC aILQSGgs02FpYqCScYHxaEc1UdGhwGl5p6DYEqFn 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"
[tester::#HD5] Received: "" (no content received)
[tester::#HD5] ^ error
[tester::#HD5] Error: Expected start of a new RESP2 value (either +, -, :, $ or *)
[tester::#HD5] Test failed
To reiterate, the second replica completes a handshake when I launch two on my local machine.
The codebase is quite large by now, and I’m not sure what part of the code would be helpful to include, but has anybody encountered a similar issue?