Stage #HC6 (Replication - The INFO command on a replica) error: dial tcp 127.0.0.1:6380: connect: connection refused

Here my code to implement Redis in C/C++. Now I has 2 problem with 2 branches:

  • In branch master, I am stuck at Stage #XV6 (Replication - ACKs with no commands). The console show error:
    [tester::#XV6] Received: “” (no content received)
    [tester::#XV6] ^ error
    [tester::#XV6] Error: Expected start of a new RESP2 value (either +, -, :, $ or *)

  • In branch Refactor-asio, I tried to use async methods and fail at the Stage:
    The INFO command on a replica #hc6. It shows error: dial tcp 127.0.0.1:6380: connect: connection refused

  • When I run both branches with 2 test cases local (using redis-server, redis-cli), every thing OK. I has debug every thing but could not find the solution. If you want to write log in my code, you can use the options in the file RedisDef.h. Thanks you for your support

Hey @vnmanh29, looks like your async implementation is breaking because of writing to ptmp_file.

I was able to get stage #HC6 to pass by doing either of these:

(a) Bypassing fopen and everything that follows:

(b) Passing a nullptr into ReadRdbFileReply and avoiding writes:

Let me know if you’d like help debugging this further!

1 Like

Hi @andy1li . Thanks your support. I see your solution that avoid to write rdb data to file.

  • why we don’t open and write the binary rdb file? What is the root cause make I fail at test case HC6

  • When does the program receive the rdb data from its master and write it? I think it follow receiving FULLRESYNC command.

  • And can you help me in branch master, with the test case #XV6

1 Like

Thanks your support. I see your solution that avoid to write rdb data to file.

  • why we don’t open and write the binary rdb file?

It’s not really a solution :sweat_smile:, but more of a starting point for identifying the problem.

A more useful question might be: why does writing to a file break the async implementation?

  • What is the root cause make I fail at test case HC6

To be honest, I’m not entirely sure. I only learned about Asio yesterday through your code.

  • When does the program receive the rdb data from its master and write it? I think it follow receiving FULLRESYNC command.
  • And can you help me in branch master, with the test case #XV6

Let’s focus on solving the current issue first before tackling the others.

Here are a couple of things you could try:

  1. Use an async version of file writing.

  2. Keep the handshake synchronous, and only switch to async after it’s complete.

Let me know if either approach works!

  • Me too. In the first version, I use system call with file descriptor (read(), write() on posix standard) but I want to try to implement with Asio library. And I guess that mixed between blocking-operation (fwrite()) makes this issue (not sure). Instead, I use read(), write() on file descriptor for the regular file and it solves this issue. But the read(), write() method also blocking-operation, maybe I will replace them in the next refactor :grin: Thank for your suggestion.
  • And about the test case #XV6, It is my code. the master also propagates the GETACK command, and the replica read both binary data and this command at the same time. So I wrote both to persistent file, instead of only binary data :upside_down_face: . Thank for your support again.
1 Like

the master also propagates the GETACK command, and the replica read both binary data and this command at the same time

Ideally, your implementation should be able to handle cases where multiple commands are read in a single read operation.

1 Like

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