EOF after reading FULLRESYNC

I’m stuck on Stage#yd3 .

After reading FULLRESYNC command, when replica starts to read RDB file, it gets EOF but on some occasions it reads RDB file but gets EOF when reading command REPLCONF GETACK * thus loop breaks and gives this error

Here are my logs:

[tester::#XV6] Received: "" (no content received)
[tester::#XV6]            ^ error
[tester::#XV6] Error: Expected start of a new RESP2 value (either +, -, :, $ or *)
[tester::#XV6] Test failed

And here’s a snippet of my code:

func (kv *KVStore) SendHandshake(master *net.Conn) {

	rdr := bufio.NewReader(*master)
	buff := []string{"PING"}
	res := []byte{}
	fmt.Println("sent ping")
	(*master).Write([]byte(resp.ToArray(buff)))
	res, _ = rdr.ReadBytes('\n')
	fmt.Println(string(res))

	fmt.Println("sent replconf1")
	buff = []string{"REPLCONF", "listening-port", kv.Info.Port}
	(*master).Write(resp.ToArray(buff))
	res, _ = rdr.ReadBytes('\n')
	fmt.Println(string(res))

	fmt.Println("sent replconf2")
	buff = []string{"REPLCONF", "capa", "psync2"}
	(*master).Write(resp.ToArray(buff))
	res, _ = rdr.ReadBytes('\n')
	fmt.Println(string(res))

	fmt.Println("sent psync")
	(*master).Write(resp.ToArray([]string{"PSYNC", "?", "-1"}))
	res, _ = rdr.ReadBytes('\n')
	fmt.Println(string(res))

}

Here is complete code:

1 Like

Thanks for sharing the complete code! I will take a look by the end of next week.

Hi @vansh845, looks like you’ve got past this stage — do you happen to remember what was wrong? Would love to see if we can improve the tester / instructions.

That passed by chance, still same problem…

I tested with redis-tester locally, tests are passing with it

Sounds like a race condition is involved. I’lll take a look by the end of next week.

I figured it out, not a race condition. What I didn’t know was bufio reader uses an internal buffer to store data temporarily to avoid frequent IO and I was using a bufio reader for handshake and a new one for handling commands. So the one used for replication handshake read all data from net.Conn into its internal buffer and the reader for handling commands was starting with a new empty buffer loosing the previous data, resulting in EOF.

1 Like

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