Command processing (#YG4) write to broken pipe

I’m stuck on stage13 - Command Processing.

I’ve tried receive as much data as possible from master, but it seems that the master is not send any msg to my replica(6380).

Here are my logs:

remote: [replication-13] Running tests for Replication > Stage #13: Command Processing
remote: [replication-13] Master is running on port 6379
remote: [replication-13] $ ./spawn_redis_server.sh --port 6380 --replicaof localhost 6379
remote: [replication-13] Received ["ping"]
remote: [replication-13] master: Sent "PONG"
remote: [replication-13] Received ["REPLCONF", "listening-port", "6380"]
remote: [replication-13] master: Sent "OK"
remote: [replication-13] Received ["REPLCONF", "capa", "eof", "psync2"]
remote: [replication-13] master: Sent "OK"
remote: [replication-13] Received ["PSYNC", "?", "-1"]
remote: [replication-13] master: Sent "FULLRESYNC 75cd7bc10c49047e0d163660f3b90625b1af31dc 0"
remote: [replication-13] Sent RDB file.
remote: [replication-13] master: $ redis-cli SET foo 123
remote: [replication-13] write tcp 127.0.0.1:6379->127.0.0.1:53352: write: broken pipe
remote: [replication-13] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)

And here’s a snippet of my code:

master.write("*1\r\n$4\r\nping\r\n".as_bytes()).expect("Write to mas ter failed");

if is_response_contains(&mut master, "PONG") {
    master
        .write(format!("*3\r\n$8\r\nREPLCONF\r\n$14\r\nlistening-port\r\n$4\r\n{}\r\n", port).as_bytes())
        .expect("Write to master failed");

    if is_response_contains(&mut master, "OK") {
        master
            .write("*4\r\n$8\r\nREPLCONF\r\n$4\r\ncapa\r\n$3\r\neof\r\n$6\r\npsync2\r\n".as_bytes())
            .expect("Write to master failed");

        if is_response_contains(&mut master, "OK") {
            master.write("*3\r\n$5\r\nPSYNC\r\n$1\r\n?\r\n$2\r\n-1\r\n".as_bytes()).expect("Write to master failed");

            // let server_config_cloned = server_config.clone();
            // let store_cloned = store.clone();
            // let repl_server_map_cloned = repl_server_map.clone();

            // handler(master, store_cloned, repl_server_map_cloned, server_config_cloned);

            // for _ in 0..10 {
            //     let mut a = [0u8; 1024];
            //     let size = master.read(&mut a).unwrap();

            //     println!("read from master:{size},{}", String::from_utf8_lossy(&a[..size]));
            // }
        }
    }
}

Similar to this issue:

It seems that the master disconnected to redis-cli.

Hey @zRains! Are you still facing issues with this?

My guess here is that this means the connection was closed after the handshake, instead of remaining open to receive propagated commands.

Thank you for the reply. The issue has been resolved; it was caused by not using another thread to execute the slave.

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

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