# Replication stage (#NA2) No ACKs received from replicas?

**URL:** <https://forum.codecrafters.io/t/replication-stage-na2-no-acks-received-from-replicas/63>\
**Category:** Challenges\
**Tags:** challenge:redis\
**Created:** [April 8, 2024, 8:23pm UTC](https://forum.codecrafters.io/t/replication-stage-na2-no-acks-received-from-replicas/63 "2024-04-08T20:23:56Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![codesbyayush](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/codesbyayush/32/36_2.png) [@codesbyayush](https://forum.codecrafters.io/u/codesbyayush)\
**Post date:** [April 8, 2024, 8:23pm UTC](https://forum.codecrafters.io/t/replication-stage-na2-no-acks-received-from-replicas/63/1 "2024-04-08T20:23:56Z")

</div>

I’m stuck on replication state 18 redis

Here are my logs:

```auto
[replication-18] client: $ redis-cli SET foo 123
[replication-18] Received "OK"
[replication-18] client: $ redis-cli WAIT 1 500
[replication-18] Testing Replica : 1
[replication-18] Received ["SET", "foo", "123"]
[your_program] ["set", "foo", "123", ""]
[your_program] ["wait", "1", "500", ""]
[replication-18] Received ["REPLCONF", "GETACK", "*"]
[replication-18] replica-1: $ redis-cli REPLCONF ACK 197
[replication-18] Testing Replica : 2
[replication-18] Received ["SET", "foo", "123"]
[your_program] ["replconf", "ack", "197", ""]
[replication-18] Received ["REPLCONF", "GETACK", "*"]
[replication-18] Testing Replica : 3
[replication-18] Received ["SET", "foo", "123"]
[replication-18] Received ["REPLCONF", "GETACK", "*"]
[replication-18] Received: ""
[replication-18] ^ error

```

---

<div class="post-metadata">

**Author:** ![codesbyayush](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/codesbyayush/32/36_2.png) [@codesbyayush](https://forum.codecrafters.io/u/codesbyayush)\
**Post date:** [April 8, 2024, 8:25pm UTC](https://forum.codecrafters.io/t/replication-stage-na2-no-acks-received-from-replicas/63/2 "2024-04-08T20:25:27Z")

</div>

> **[GitHub - codesbyayush/codecrafters-redis-typescript](https://github.com/codesbyayush/codecrafters-redis-typescript)**
>
> Contribute to codesbyayush/codecrafters-redis-typescript development by creating an account on GitHub.

github link for the code. After the expected acknowledgements the response is not sent.

---

<div class="post-metadata">

**Author:** ![seg4lt](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/seg4lt/32/19701_2.png) [@seg4lt](https://forum.codecrafters.io/u/seg4lt)\
**Post date:** [April 11, 2024, 6:10pm UTC](https://forum.codecrafters.io/t/replication-stage-na2-no-acks-received-from-replicas/63/3 "2024-04-11T18:10:55Z")

</div>

Interesting. I am also seeing the same issue I think. I wish someone takes a look at this. I was asserting if I get proper ‘REPL ACK ’ back but, my server doesn’t receive anything from slave, so test doesn’t pass.

---

<div class="post-metadata">

**Author:** ![h10666](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/h10666/32/102_2.png) [@h10666](https://forum.codecrafters.io/u/h10666)\
**Post date:** [April 15, 2024, 3:48pm UTC](https://forum.codecrafters.io/t/replication-stage-na2-no-acks-received-from-replicas/63/4 "2024-04-15T15:48:28Z")

</div>

I’m stuck on Replication 18 WAIT with multiple commands.

I tried to print message receive from slave, but i receive nothing in this stage. I got correct message in my environment.

Here are my logs:

```auto
[your_program] server receive *3
[your_program] $4
[your_program] WAIT
[your_program] $1
[your_program] 3
[your_program] $3
[your_program] 500
[your_program] 
[your_program] Server offset: 0
[your_program] Master try to get offset of 12
[your_program] Master try to get offset of 11
[your_program] Master try to get offset of 10
[your_program] Master try to get offset of 9
[your_program] Master try to get offset of 8
[your_program] Master try to get offset of 7
[your_program] Master try to get offset of 6
[your_program] Master try to get offset of 5
[replication-17] client: Received bytes: ":0\r\n"
[replication-17] client: Received RESP value: 0
[replication-17] Expected 8, got 0
[replication-17] Test failed
[replication-17] Terminating program
[replication-17] Program terminated successfully

```

And here’s a snippet of my code:

```cpp
while (true)
  {
    bool reply = (server->ismaster) || (clientfd != server->masterfd);
    int cur_location = 0;
    std::string replyMsg(server->clients[clientfd].buffer.begin(), server->clients[clientfd].buffer.end());
    ReplyParser parser(replyMsg);
    cur_location = 0;
    int msg_len = parser.parseReply(cur_location);
    if (msg_len <= 0)// uncomplete message
    { 
      return -1;
    }
    
    std::cout << "server receive " << replyMsg<< std::endl;
....
    case WAIT:{
        auto now = std::chrono::steady_clock().now();
        
        std::chrono::milliseconds duration(std::stoi(parser.tokens[1]));
        auto expire_timepoint = now + duration;
        std::thread t(waitprocess, server, clientfd, std::stoi(parser.tokens[0]), expire_timepoint);
        t.detach();
    }
....
waitprocess(){
....
for (auto it = server->needReplica_fd.begin(); it != server->needReplica_fd.end();)
    {
      std::cout<<"Master try to get offset of "<<*it<<std::endl;
      if(send(*it, "*3\r\n$8\r\nREPLCONF\r\n$6\r\nGETACK\r\n$1\r\n*\r\n", 37, 0)<0)std::cout<<"Send GETACK ERROR"<<std::endl;
      it = server->needReplica_fd.erase(it);
    }
....
}

```

---

<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 16, 2024, 12:36pm UTC](https://forum.codecrafters.io/t/replication-stage-na2-no-acks-received-from-replicas/63/5 "2024-04-16T12:36:58Z")

</div>

Yep, I think we just need proper instructions here - it is **expected** that some slaves will not respond to ACKs, that’s what we explicitly test in this stage.

---

<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 16, 2024, 12:37pm UTC](https://forum.codecrafters.io/t/replication-stage-na2-no-acks-received-from-replicas/63/6 "2024-04-16T12:37:13Z")

</div>

Will keep this open until we’ve improved the instructions!

---

<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 13, 2024, 11:53am UTC](https://forum.codecrafters.io/t/replication-stage-na2-no-acks-received-from-replicas/63/7 "2024-05-13T11:53:09Z")

</div>

Just adding a quick note – we haven’t updated the instructions here yet, but we do have better logs now:

 ![Screenshot 2024-05-13 at 12.52.32](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/1X/8736673ddb19bc8c42ce0452a631179c33438c63.png)

---

<div class="post-metadata">

**Author:** ![SegniAdebaGodsSon](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/segniadebagodsson/32/13_2.png) [@SegniAdebaGodsSon](https://forum.codecrafters.io/u/SegniAdebaGodsSon)\
**Post date:** [May 14, 2024, 12:08pm UTC](https://forum.codecrafters.io/t/replication-stage-na2-no-acks-received-from-replicas/63/8 "2024-05-14T12:08:04Z")

</div>

Same here, been stuck on this stage for embarrassingly long time. The replicas are not responding except the first replica for some reason.

 ![stage 18](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/1X/e750f3bef7db2d5f01e25744e6b792d9044f8728.jpeg)

If anyone knows the reason for this a help is greatly appreciated, couldn’t come up with a working solution for this one I’m afraid.

---

<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 14, 2024, 12:17pm UTC](https://forum.codecrafters.io/t/replication-stage-na2-no-acks-received-from-replicas/63/9 "2024-05-14T12:17:12Z")

</div>

> [@rohitpaulk](#):
>
> it is **expected** that some slaves will not respond to ACKs, that’s what we explicitly test in this stage.

As noted above (^), it is **expected** that some slaves will not respond to ACKs in this stage.

---

<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, 2:09am UTC](https://forum.codecrafters.io/t/replication-stage-na2-no-acks-received-from-replicas/63/10 "2024-06-04T02:09:06Z")

</div>

Note: I’ve updated the title of this post to include the stage ID (#NA2). 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:** ![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 18, 2024, 12:05pm UTC](https://forum.codecrafters.io/t/replication-stage-na2-no-acks-received-from-replicas/63/11 "2024-06-18T12:05:30Z")

</div>

The logs now clearly mention when a replica ACKs vs. doesn’t ACK a message - marking as closed!

---

<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 23, 2024, 12:05pm UTC](https://forum.codecrafters.io/t/replication-stage-na2-no-acks-received-from-replicas/63/12 "2024-06-23T12:05:55Z")

</div>

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