# \#xi4 Stuck here because the test case seems to time out for some reason

**URL:** <https://forum.codecrafters.io/t/xi4-stuck-here-because-the-test-case-seems-to-time-out-for-some-reason/8442>\
**Category:** Challenges\
**Tags:** challenge:bittorrent\
**Created:** [April 8, 2025, 3:56pm UTC](https://forum.codecrafters.io/t/xi4-stuck-here-because-the-test-case-seems-to-time-out-for-some-reason/8442 "2025-04-08T15:56:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhishek-7901](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/abhishek-7901/32/6674_2.png) [@abhishek-7901](https://forum.codecrafters.io/u/abhishek-7901)\
**Post date:** [April 8, 2025, 3:56pm UTC](https://forum.codecrafters.io/t/xi4-stuck-here-because-the-test-case-seems-to-time-out-for-some-reason/8442/1 "2025-04-08T15:56:21Z")

</div>

I’m stuck on Stage #(xi4) because the test cases are timing out, I am not certain where the following is going wrong

Here are my logs:

```auto
A%2F%2F127.0.0.1:34319%2Fannounce"
[tester::#XI4] Tracker started on address 127.0.0.1:34319...
[tester::#XI4] 
[tester::#XI4] Peer listening on address: 127.0.0.1:41577
[tester::#XI4] Waiting to receive handshake message
[tester::#XI4] Received handshake: [infohash: ad42ce8109f54c99613ce38f9b4d87e70f24a165, peer_id: 2d5043303030312d766679665558696379325442]
[tester::#XI4] 
[tester::#XI4] Sending back handshake with peer_id: 655df499a29247c98c62f45bdb307ea4b2d400ac
[tester::#XI4] Sending bitfield message
[tester::#XI4] Sending extension handshake
[tester::#XI4] Waiting to receive extension handshake message
[your_program] 68
[your_program] message is <Buffer 05 e0>
[tester::#XI4] Received extension handshake with payload: d1:md11:ut_metadatai1e6:ut_pexi2eee
[tester::#XI4] Checking metadata extension id received
[tester::#XI4] timed out, test exceeded 10 seconds
[tester::#XI4] Test failed

```

And here’s a snippet of my code: Rest of the code is committed

```javascript
  else if (command === "magnet_handshake"){
    const magLink = process.argv[3]
    const magnetParser = new MagnetParser(magLink)
    const p2pClient = new PeerCommunication(magnetParser)

    const peer = (await magnetParser.getPeers())[0]
    
    let {client, response} = await p2pClient.initiateHandShake(peer)
    console.log(response.length)
    const msg = await p2pClient.waitForBitField(client)

    console.log("message is", msg)
    const reserved = response.subarray(20, 28)
    if (reserved[5] & 0x10) {
      const bdict = bencode({m : {ut_metadata : 1, ut_pex : 2}})
      p2pClient.createExtensionHandshake(client, Buffer.from(bdict, "binary"))

      const { blockData} = await p2pClient.waitForExtensionHandshake(client);
    }

    client.destroy()
    client = null

    p2pClient.printPeerId(peer)

  }

```

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [April 8, 2025, 6:14pm UTC](https://forum.codecrafters.io/t/xi4-stuck-here-because-the-test-case-seems-to-time-out-for-some-reason/8442/4 "2025-04-08T18:14:19Z")

</div>

Hey @abhishek-7901, the timeout is caused by the extra handshake at the end:

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/9/9ad7f3d16b877a7df8089e2880aff4208c9fe659.png)

---

<div class="post-metadata">

**Author:** ![abhishek-7901](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/abhishek-7901/32/6674_2.png) [@abhishek-7901](https://forum.codecrafters.io/u/abhishek-7901)\
**Post date:** [April 9, 2025, 12:38pm UTC](https://forum.codecrafters.io/t/xi4-stuck-here-because-the-test-case-seems-to-time-out-for-some-reason/8442/6 "2025-04-09T12:38:21Z")

</div>

thanks brother, silly from my end

---

<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:** [April 14, 2025, 12:38pm UTC](https://forum.codecrafters.io/t/xi4-stuck-here-because-the-test-case-seems-to-time-out-for-some-reason/8442/7 "2025-04-14T12:38:59Z")

</div>

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