# Stuck on Redis Replication #ZN8

**URL:** <https://forum.codecrafters.io/t/stuck-on-redis-replication-zn8/387>\
**Category:** Challenges\
**Tags:** challenge:redis\
**Created:** [May 14, 2024, 5:32pm UTC](https://forum.codecrafters.io/t/stuck-on-redis-replication-zn8/387 "2024-05-14T17:32:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jbordhen](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/jbordhen/32/343_2.png) [@Jbordhen](https://forum.codecrafters.io/u/Jbordhen)\
**Post date:** [May 14, 2024, 5:32pm UTC](https://forum.codecrafters.io/t/stuck-on-redis-replication-zn8/387/1 "2024-05-14T17:32:26Z")

</div>

I am trying this challenge in Golang. As you can see from the log, I am getting the same output from both master and slave. But the test is getting different response.

```auto

Debug = true
[replication-11] Running tests for Replication > Stage #11: Single-replica propagation
[replication-11] $ ./spawn_redis_server.sh --port 6379
[your_program] Logs from your program will appear here!
[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] Accepted connection from [::1]:56026
[your_program] Accepted connection from [::1]:56012
[your_program] master 8371b4fb1155b71f4a04d3e1bc3e18c4a990aeeb +PONG
[your_program] 
[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"
[your_program] master 8371b4fb1155b71f4a04d3e1bc3e18c4a990aeeb +OK
[your_program] 
[replication-11] replica: Received bytes: "+OK\r\n"
[replication-11] replica: Received RESP value: "OK"
[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"
[your_program] master 8371b4fb1155b71f4a04d3e1bc3e18c4a990aeeb +OK
[your_program] 
[replication-11] replica: Received bytes: "+OK\r\n"
[replication-11] replica: Received RESP value: "OK"
[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"
[your_program] master 8371b4fb1155b71f4a04d3e1bc3e18c4a990aeeb +FULLRESYNC 8371b4fb1155b71f4a04d3e1bc3e18c4a990aeeb 0
[your_program] 
[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] slaveList [0xc00009c040]
[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] *3
[your_program] $3
[your_program] SET
[your_program] $3
[your_program] foo
[your_program] $3
[your_program] 123
[your_program] 
[your_program] Write to slave 6fc33975-4b18-4d16-ae2f-716f7e67eb3d@ [::1]:56026Command SET: *3
[your_program] $3
[your_program] SET
[your_program] $3
[your_program] foo
[your_program] $3
[your_program] 123
[your_program] master 8371b4fb1155b71f4a04d3e1bc3e18c4a990aeeb +OK
[your_program] 
[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] *3
[your_program] $3
[your_program] SET
[your_program] $3
[your_program] bar
[your_program] $3
[your_program] 456
[your_program] 
[your_program] Write to slave 6fc33975-4b18-4d16-ae2f-716f7e67eb3d@ [::1]:56026Command SET: *3
[your_program] $3
[your_program] SET
[your_program] $3
[your_program] bar
[your_program] $3
[your_program] 456
[your_program] master 8371b4fb1155b71f4a04d3e1bc3e18c4a990aeeb +OK
[your_program] 
[replication-11] client: Received bytes: "+OK\r\n"
[replication-11] client: Received RESP value: "OK"
[replication-11] Received "OK"
[replication-11] client: $ redis-cli SET baz 789
[replication-11] client: Sent bytes: "*3\r\n$3\r\nSET\r\n$3\r\nbaz\r\n$3\r\n789\r\n"
[replication-11] client: Received bytes: "+OK\r\n"
[replication-11] client: Received RESP value: "OK"
[your_program] *3
[your_program] $3
[your_program] SET
[your_program] $3
[your_program] baz
[your_program] $3
[your_program] 789
[your_program] 
[your_program] Write to slave 6fc33975-4b18-4d16-ae2f-716f7e67eb3d@ [::1]:56026Command SET: *3
[your_program] $3
[your_program] SET
[your_program] $3
[your_program] baz
[your_program] $3
[replication-11] Received "OK"
[replication-11] Sent 3 SET commands to master successfully.
[replication-11] replica: Expecting "SET foo 123" to be propagated
[replication-11] replica: Received bytes: "*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$3\r\n123\r\n"
[replication-11] replica: Received RESP value: ["SET", "foo", "123"]
[replication-11] Received ["SET", "foo", "123"]
[replication-11] replica: Expecting "SET bar 456" to be propagated
[your_program] 789
[replication-11] Received: "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
[replication-11] ^ error
[replication-11] Error: "\x00" is not a valid start of a RESP2 value (expected +, -, :, $ or *)
[replication-11] Test failed
[replication-11] Terminating program
[your_program] master 8371b4fb1155b71f4a04d3e1bc3e18c4a990aeeb +OK
[your_program] 
[your_program] Error reading from connection: read tcp [::1]:6379->[::1]:56026: read: connection reset by peer
[your_program] Error reading from connection: EOF
[replication-11] Program terminated successfully`Preformatted text`

```

Thank you 😀.

---

<div class="post-metadata">

**Author:** ![Jbordhen](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/jbordhen/32/343_2.png) [@Jbordhen](https://forum.codecrafters.io/u/Jbordhen)\
**Post date:** [May 17, 2024, 2:52pm UTC](https://forum.codecrafters.io/t/stuck-on-redis-replication-zn8/387/2 "2024-05-17T14:52:54Z")

</div>

So, I had to replace the args with “\x00” and the test passed.

Any idea why I have to remove “\x00” this when it’s the exact same string?

Correct version

```auto
				for _, slave := range server.SlaveList {
					input := strings.Replace(input, "\x00", "", -1)
					_, err := slave.conn.Write([]byte(input))

					// fmt.Printf("Write to slave %s@ %s", slave.id, slave.conn.RemoteAddr())

					if err != nil {
						fmt.Println("Error write to slave: ", err.Error())
						fmt.Println(slave.conn)
						slave.conn.Close()
						continue
					}
				}

```

Old version

```auto
				for _, slave := range server.SlaveList {
					_, err := slave.conn.Write([]byte(input))

					// fmt.Printf("Write to slave %s@ %s", slave.id, slave.conn.RemoteAddr())

					if err != nil {
						fmt.Println("Error write to slave: ", err.Error())
						fmt.Println(slave.conn)
						slave.conn.Close()
						continue
					}
				}

```

---

<div class="post-metadata">

**Author:** ![rohitpaulk](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/rohitpaulk/32/6_2.png) [@rohitpaulk](https://forum.codecrafters.io/u/rohitpaulk)\
**Post date:** [May 27, 2024, 9:43pm UTC](https://forum.codecrafters.io/t/stuck-on-redis-replication-zn8/387/3 "2024-05-27T21:43:18Z")

</div>

@Jbordhen this can happen if you’re initializing a fixed size byte array (something like `var arr [1024]byte`) but only reading a smaller amount of bytes into it. The rest of the bytes will be null bytes (`\x00`) by default.

Hard to tell if it’s exactly this without seeing how `input` is constructed, but this is the most likely cause 🙂

---

<div class="post-metadata">

**Author:** ![rohitpaulk](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/rohitpaulk/32/6_2.png) [@rohitpaulk](https://forum.codecrafters.io/u/rohitpaulk)\
**Post date:** [June 3, 2024, 7:12pm UTC](https://forum.codecrafters.io/t/stuck-on-redis-replication-zn8/387/4 "2024-06-03T19:12:18Z")

</div>

Marking as closed for now, please let us know if you still need help!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [June 4, 2024, 1:54am UTC](https://forum.codecrafters.io/t/stuck-on-redis-replication-zn8/387/5 "2024-06-04T01:54:58Z")

</div>

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](https://forum.codecrafters.io/t/upcoming-change-stages-overhaul/375).

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [June 9, 2024, 1:55am UTC](https://forum.codecrafters.io/t/stuck-on-redis-replication-zn8/387/6 "2024-06-09T01:55:45Z")

</div>

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