SOLVED: issue with Single-replica propagation stage #ZN8

I’m stuck on Single-replica propagation.

I am learning go-lang and I’m new to debugging errors in golang. But the program seems to run fine when testing manually. I’ve testing using one master node, three replica nodes and one client. PING requests from clients to replicas works fine locally. I’m not sure what the test is exactly trying to do to debug the issue?

https://github.com/thezetrax/redi-go

THIS HAS BEEN FIXED

Update: I had a bug on my application, on replica nodes I was only listening to requests from the master node. That was causing the connection refused when the client tried to connect to the replica node.

Here are my logs:

[replication-3] Running tests for Replication > Stage #3: The INFO command on a replica
[replication-3] Master is running on port 6379
[replication-3] $ ./spawn_redis_server.sh --port 6380 --replicaof localhost 6379
[replication-3] master: Received bytes: "*1\r\n$4\r\nPING\r\n"
[replication-3] master: Received RESP value: ["PING"]
[replication-3] master: Sent "PONG"
[replication-3] master: Sent bytes: "+PONG\r\n"
[replication-3] master: Received bytes: "*3\r\n$8\r\nREPLCONF\r\n$14\r\nlistening-port\r\n$4\r\n6380\r\n"
[replication-3] master: Received RESP value: ["REPLCONF", "listening-port", "6380"]
[replication-3] master: Sent "OK"
[replication-3] master: Sent bytes: "+OK\r\n"
[your_program] 2024/04/06 21:47:51 Master[localhost:6379] raw response: +PONG\r\n
[replication-3] master: Received bytes: "*5\r\n$8\r\nREPLCONF\r\n$4\r\ncapa\r\n$3\r\neof\r\n$4\r\ncapa\r\n$6\r\npsync2\r\n"
[replication-3] master: Received RESP value: ["REPLCONF", "capa", "eof", "capa", "psync2"]
[your_program] 2024/04/06 21:47:51 Master[localhost:6379] raw response: +OK\r\n
[replication-3] master: Sent "OK"
[replication-3] master: Sent bytes: "+OK\r\n"
[replication-3] master: Received bytes: "*3\r\n$5\r\nPSYNC\r\n$1\r\n?\r\n$2\r\n-1\r\n"
[replication-3] master: Received RESP value: ["PSYNC", "?", "-1"]
[your_program] 2024/04/06 21:47:51 Master[localhost:6379] raw response: +OK\r\n
[replication-3] master: Sent "FULLRESYNC 75cd7bc10c49047e0d163660f3b90625b1af31dc 0"
[replication-3] master: Sent bytes: "+FULLRESYNC 75cd7bc10c49047e0d163660f3b90625b1af31dc 0\r\n"
[replication-3] master: Sent 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"
[your_program] 2024/04/06 21:47:51 Master[localhost:6379] raw response: +FULLRESYNC 75cd7bc10c49047e0d163660f3b90625b1af31dc 0\r\n$88\r\nREDIS0011    redis-ver7.2.0
[your_program] redis-bits@ctimeused-memaof-basen;Z
[your_program] 2024/04/06 21:47:51 Connected to master: localhost:6379
[replication-3] dial tcp [::1]:6380: connect: connection refused
[replication-3] Test failed
[replication-3] Terminating program
[replication-3] Program terminated successfully

Here are the logs:

[your_program] 2024/04/07 02:43:52 PSYNC [? -1]
[replication-9] Received "FULLRESYNC a54dbf36b1f31ce6a681d95ccd78eb313e598c1a 0"
[replication-9] Test passed.
[your_program] Error accepting connection:  accept tcp [::]:6379: use of closed network connection

[replication-10] Running tests for Replication > Stage #10: Empty RDB Transfer
[replication-10] $ ./spawn_redis_server.sh --port 6379
[your_program] Redis-server listening on: 6379
[replication-10] client: $ redis-cli PING
[your_program] 2024/04/07 02:43:52 [RAW REQUEST]:  *1\r\n$4\r\nPING\r\n
[your_program] 2024/04/07 02:43:52 [RAW REQUEST]:  *1\r\n$4\r\nPING\r\n
[your_program] 2024/04/07 02:43:52 PING []
[replication-10] Received "PONG"
[replication-10] client: $ redis-cli REPLCONF listening-port 6380
[your_program] 2024/04/07 02:43:52 [RAW REQUEST]:  *3\r\n$8\r\nREPLCONF\r\n$14\r\nlistening-port\r\n$4\r\n6380\r\n
[your_program] 2024/04/07 02:43:52 REPLCONF [listening-port 6380]
[replication-10] Received "OK"
[replication-10] client: $ redis-cli REPLCONF capa psync2
[your_program] 2024/04/07 02:43:52 [RAW REQUEST]:  *3\r\n$8\r\nREPLCONF\r\n$4\r\ncapa\r\n$6\r\npsync2\r\n
[your_program] 2024/04/07 02:43:52 REPLCONF [capa psync2]
[replication-10] Received "OK"
[replication-10] client: $ redis-cli PSYNC ? -1
[your_program] 2024/04/07 02:43:52 [RAW REQUEST]:  *3\r\n$5\r\nPSYNC\r\n$1\r\n?\r\n$2\r\n-1\r\n
[your_program] 2024/04/07 02:43:52 PSYNC [? -1]
[replication-10] Received "FULLRESYNC 99e16f971c7a6a57f62985f18023cc3fb199fc71 0"
[replication-10] Received RDB file
[replication-10] Test passed.
[your_program] Error accepting connection:  accept tcp [::]:6379: use of closed network connection

[replication-11] Running tests for Replication > Stage #11: Single-replica propagation
[replication-11] $ ./spawn_redis_server.sh --port 6379
[your_program] Redis-server listening on: 6379
[replication-11] replica: $ redis-cli PING
[replication-11] Received: ""
[replication-11]            ^ error
[replication-11] Error: Expected start of a new RESP value (either +, -, :, $ or *)
[replication-11] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)
[your_program] Error reading from connection:  EOF

View stage instructions: https://app.codecrafters.io/courses/redis.

Marking this as solved, copying from original post:

I am facing a similar challenge for replication-11 problem. Need help in debugging this out
Running tests. Logs should appear shortly…

Debug = true

[replication-11] Running tests for Replication > Stage #11: Single-replica propagation
[replication-11] $ ./spawn_redis_server.sh --port 6379
[your_program] master - Starting the server coroutine on port 6379
[your_program] master - Server running on (‘127.0.0.1’, 6379)
[replication-11] replica: $ redis-cli PING
[replication-11] replica: Sent bytes: “*1\r\n$4\r\nPING\r\n”
[replication-11] replica: Received bytes: “+PONG\r\n”
[replication-11] replica: Received RESP value: “PONG”
[your_program] master - Waiting for the next command from the client…(‘::1’, 55828, 0, 0)
[your_program] master - Waiting for the next command from the client…(‘::1’, 55832, 0, 0)
[your_program] master - RESP parsed_req: [‘PING’] for client (‘::1’, 55832, 0, 0)
[your_program] master - Waiting for the next command from the client…(‘::1’, 55832, 0, 0)
[replication-11] Received “PONG”
[replication-11] replica: $ redis-cli REPLCONF listening-port 6380
[replication-11] replica: Sent bytes: “*3\r\n$8\r\nREPLCONF\r\n$14\r\nlistening-port\r\n$4\r\n6380\r\n”
[replication-11] replica: Received bytes: “+OK\r\n”
[replication-11] replica: Received RESP value: “OK”
[your_program] master - RESP parsed_req: [‘REPLCONF’, ‘listening-port’, ‘6380’] for client (‘::1’, 55832, 0, 0)
[your_program] master - Replica connections added for (‘::1’, 55832, 0, 0)
[your_program] master - Waiting for the next command from the client…(‘::1’, 55832, 0, 0)
[replication-11] Received “OK”
[replication-11] replica: $ redis-cli REPLCONF capa psync2
[replication-11] replica: Sent bytes: “*3\r\n$8\r\nREPLCONF\r\n$4\r\ncapa\r\n$6\r\npsync2\r\n”
[replication-11] replica: Received bytes: “+OK\r\n”
[replication-11] replica: Received RESP value: “OK”
[your_program] master - RESP parsed_req: [‘REPLCONF’, ‘capa’, ‘psync2’] for client (‘::1’, 55832, 0, 0)
[your_program] master - Waiting for the next command from the client…(‘::1’, 55832, 0, 0)
[replication-11] Received “OK”
[replication-11] replica: $ redis-cli PSYNC ? -1
[replication-11] replica: Sent bytes: “*3\r\n$5\r\nPSYNC\r\n$1\r\n?\r\n$2\r\n-1\r\n”
[replication-11] replica: Received bytes: “+FULLRESYNC 8371b4fb1155b71f4a04d3e1bc3e18c4a990aeeb 0\r\n”
[replication-11] replica: Received RESP value: “FULLRESYNC 8371b4fb1155b71f4a04d3e1bc3e18c4a990aeeb 0”
[replication-11] Received “FULLRESYNC 8371b4fb1155b71f4a04d3e1bc3e18c4a990aeeb 0”
[replication-11] Reading RDB file…
[your_program] master - RESP parsed_req: [‘PSYNC’, ‘?’, ‘-1’] for client (‘::1’, 55832, 0, 0)
[your_program] master - Waiting for the next command from the client…(‘::1’, 55832, 0, 0)
[replication-11] replica: 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”
[replication-11] Received RDB file
[replication-11] client: $ redis-cli SET foo 123
[replication-11] client: Sent bytes: “*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$3\r\n123\r\n”
[replication-11] client: Received bytes: “+OK\r\n”
[replication-11] client: Received RESP value: “OK”
[your_program] master - RESP parsed_req: [‘SET’, ‘foo’, ‘123’] for client (‘::1’, 55828, 0, 0)
[your_program] sent b’*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$3\r\n123\r\n’ to replica (‘::1’, 55832, 0, 0)
[your_program] master - Waiting for the next command from the client…(‘::1’, 55828, 0, 0)
[replication-11] Received “OK”
[replication-11] client: $ redis-cli SET bar 456
[replication-11] client: Sent bytes: “*3\r\n$3\r\nSET\r\n$3\r\nbar\r\n$3\r\n456\r\n”
[your_program] master - RESP parsed_req: [‘SET’, ‘bar’, ‘456’] for client (‘::1’, 55828, 0, 0)
[your_program] sent b’*3\r\n$3\r\nSET\r\n$3\r\nbar\r\n$3\r\n456\r\n’ to replica (‘::1’, 55832, 0, 0)
[your_program] master - Waiting for the next command from the client…(‘::1’, 55828, 0, 0)
[replication-11] Received: “” (no content received)
[replication-11] ^ error
[replication-11] Error: Expected start of a new RESP2 value (either +, -, :, $ or *)
[replication-11] Test failed
[replication-11] Terminating program
[replication-11] Program terminated successfully

I am able to manually setup a master, one replica and lot of Redis-cli separate clients to test this out. But I am unable to pass this stage

@Jothikumar-ekanath I don’t think this issue is related (the stage is same, but issue seems different), mind creating a separate topic along with with a snippet of your code?

Note: I’ve updated the title of this post to include the stage ID (#ZN8). You can learn about the stages rename here: Upcoming change: Stages overhaul.