# Command processing (#YG4) write to broken pipe

**URL:** <https://forum.codecrafters.io/t/command-processing-yg4-write-to-broken-pipe/115>\
**Category:** Challenges\
**Tags:** challenge:redis\
**Created:** [April 14, 2024, 3:15pm UTC](https://forum.codecrafters.io/t/command-processing-yg4-write-to-broken-pipe/115 "2024-04-14T15:15:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zRains](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/zrains/32/99_2.png) [@zRains](https://forum.codecrafters.io/u/zRains)\
**Post date:** [April 14, 2024, 3:15pm UTC](https://forum.codecrafters.io/t/command-processing-yg4-write-to-broken-pipe/115/1 "2024-04-14T15:15:51Z")

</div>

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:

```auto
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:

```rust
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]));
            // }
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![zRains](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/zrains/32/99_2.png) [@zRains](https://forum.codecrafters.io/u/zRains)\
**Post date:** [April 14, 2024, 3:27pm UTC](https://forum.codecrafters.io/t/command-processing-yg4-write-to-broken-pipe/115/2 "2024-04-14T15:27:02Z")

</div>

Similar to this issue:

> [@Replication 13 - Unclear that multiple commands can be received at once](https://forum.codecrafters.io/t/replication-13-unclear-that-multiple-commands-can-be-received-at-once/46/12):
>
> Facing a similar issue, my instance is not receiving some bytes from the server The RDB file bytes are never received

It seems that the master disconnected to redis-cli.

---

<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:** [April 23, 2024, 1:06pm UTC](https://forum.codecrafters.io/t/command-processing-yg4-write-to-broken-pipe/115/3 "2024-04-23T13:06:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zRains](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/zrains/32/99_2.png) [@zRains](https://forum.codecrafters.io/u/zRains)\
**Post date:** [April 25, 2024, 3:40am UTC](https://forum.codecrafters.io/t/command-processing-yg4-write-to-broken-pipe/115/4 "2024-04-25T03:40:30Z")

</div>

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

---

<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:** [May 9, 2024, 10:58am UTC](https://forum.codecrafters.io/t/command-processing-yg4-write-to-broken-pipe/115/5 "2024-05-09T10:58:24Z")

</div>

Closed on May 9, 2024, 10:58am UTC

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

---

<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, 5:38am UTC](https://forum.codecrafters.io/t/command-processing-yg4-write-to-broken-pipe/115/6 "2024-06-04T05:38:11Z")

</div>

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