# Test runner is giving error-msg "provided invalid infohash" and timeout on download

**URL:** <https://forum.codecrafters.io/t/test-runner-is-giving-error-msg-provided-invalid-infohash-and-timeout-on-download/4794>\
**Category:** General\
**Tags:** challenge:bittorrent\
**Created:** [February 10, 2025, 7:18pm UTC](https://forum.codecrafters.io/t/test-runner-is-giving-error-msg-provided-invalid-infohash-and-timeout-on-download/4794 "2025-02-10T19:18:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt2843](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/matt2843/32/4832_2.png) [@Matt2843](https://forum.codecrafters.io/u/Matt2843)\
**Post date:** [February 10, 2025, 7:18pm UTC](https://forum.codecrafters.io/t/test-runner-is-giving-error-msg-provided-invalid-infohash-and-timeout-on-download/4794/1 "2025-02-10T19:18:31Z")

</div>

Hi, it seems like the test runner is running against a file: “/tmp/torrents925035392/codercat.gif.torrent” I’ve decoded the file and encoded the info dictionary and Sha1 hashed which results in hash:

c77829d2a77d6516f88cd7a3de1a26abcbfab0db

And i’m getting: {“failure reason”:“provided invalid infohash”}

My info-hash is passing all the tests; and it seems to only be a problem with this torrent file? Furthermore when the test runner decides to run a test against another torrent; my client correctly downloads all the pieces, but it errors on a timeout. I’ve tried to multi-thread the download of piece-blocks, but to no avail.

My code is here: [GitHub - Matt2843/codecrafters-bittorrent-zig](https://github.com/Matt2843/codecrafters-bittorrent-zig)

---

<div class="post-metadata">

**Author:** ![Matt2843](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/matt2843/32/4832_2.png) [@Matt2843](https://forum.codecrafters.io/u/Matt2843)\
**Post date:** [February 10, 2025, 7:27pm UTC](https://forum.codecrafters.io/t/test-runner-is-giving-error-msg-provided-invalid-infohash-and-timeout-on-download/4794/2 "2025-02-10T19:27:31Z")

</div>

i’ve base64 encoded the file “codercat.gif.torrent” and printed it to stdout; such that i could get a copy of it locally. now i’ve uploaded it to [https://torrent-metadata.vercel.app/](https://torrent-metadata.vercel.app/) which reports the same info-hash as my program:  
`c77829d2a77d6516f88cd7a3de1a26abcbfab0db`

Here’s the URL i’m sending a GET request to:

`http://bittorrent-test-tracker.codecrafters.io/announce?info_hash=%C7x)%D2%A7%7De%16%F8%8C%D7%A3%DE%1A&%AB%CB%FA%B0%DB&peer_id=-mab-ztorrent-001224&port=6881&uploaded=0&downloaded=0&left=2994120&compact=1`

---

<div class="post-metadata">

**Author:** ![Matt2843](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/matt2843/32/4832_2.png) [@Matt2843](https://forum.codecrafters.io/u/Matt2843)\
**Post date:** [February 10, 2025, 7:42pm UTC](https://forum.codecrafters.io/t/test-runner-is-giving-error-msg-provided-invalid-infohash-and-timeout-on-download/4794/3 "2025-02-10T19:42:07Z")

</div>

Regarding the download timeout here’s the debug info:

```auto
remote: [your_program] discovering peers @ 70edcac2611a8829ebf467a6849f5d8408d9d8f4
remote: [your_program] http://bittorrent-test-tracker.codecrafters.io/announce?info_hash=p%ED%CA%C2a%1A%88)%EB%F4g%A6%84%9F%5D%84%08%D9%D8%F4&peer_id=-mab-ztorrent-001224&port=6881&uploaded=0&downloaded=0&left=2549700&compact=1
remote: [your_program] download block index=0 begin=0 len=16384
remote: [your_program] download block index=0 begin=32768 len=16384
remote: [your_program] download block index=0 begin=16384 len=16384
remote: [your_program] download block index=0 begin=81920 len=16384
remote: [your_program] download block index=0 begin=65536 len=16384
remote: [your_program] download block index=0 begin=49152 len=16384

... truncated

remote: [your_program] download block index=9 begin=114688 len=16384
remote: [your_program] download block index=9 begin=98304 len=16384
remote: [your_program] download block index=9 begin=131072 len=16384
remote: [your_program] download block index=9 begin=147456 len=16384
remote: [your_program] download block index=9 begin=163840 len=16384
remote: [your_program] download block index=9 begin=180224 len=10180
remote: [tester::#JV8] execution timed out
remote: [tester::#JV8] Test failed

```

---

<div class="post-metadata">

**Author:** ![sarp](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/sarp/32/1082_2.png) [@sarp](https://forum.codecrafters.io/u/sarp)\
**Post date:** [February 10, 2025, 8:02pm UTC](https://forum.codecrafters.io/t/test-runner-is-giving-error-msg-provided-invalid-infohash-and-timeout-on-download/4794/4 "2025-02-10T20:02:49Z")

</div>

Hi Matt2843,  
The info hash tester is expecting is indeed `c77829d2a77d6516f88cd7a3de1a26abcbfab0db`

You can find the torrent files here:

> **[bittorrent-tester/torrents at main · codecrafters-io/bittorrent-tester](https://github.com/codecrafters-io/bittorrent-tester/tree/main/torrents)**
>
> Tester for the "Build your own BitTorrent" challenge - codecrafters-io/bittorrent-tester

You can open them with a torrent program like qBittorrent to validate the info hash (although we’re in agreement on the correct value)

The correct URL we’re expecting to request peers is this:  
`http://bittorrent-test-tracker.codecrafters.io/announce?compact=1&downloaded=0&info_hash=%C7x%29%D2%A7%7De%16%F8%8C%D7%A3%DE%1A%26%AB%CB%FA%B0%DB&left=2994120&peer_id=%1E%83FP%81%96%24+N%C2%96%F7%B6ep%D9f%97A%88&port=6881&uploaded=0`

If you look carefully, parts of your info hash in the URL you provided seem to be incorrect:  
`http://bittorrent-test-tracker.codecrafters.io/announce?info_hash=%C7x)%D2%A7%7De%16%F8%8C%D7%A3%DE%1A&%AB%CB%FA%B0%DB&peer_id=-mab-ztorrent-001224&port=6881&uploaded=0&downloaded=0&left=2994120&compact=1`

Hope this helps, let me know if you have other questions

---

<div class="post-metadata">

**Author:** ![Matt2843](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/matt2843/32/4832_2.png) [@Matt2843](https://forum.codecrafters.io/u/Matt2843)\
**Post date:** [February 11, 2025, 7:48pm UTC](https://forum.codecrafters.io/t/test-runner-is-giving-error-msg-provided-invalid-infohash-and-timeout-on-download/4794/5 "2025-02-11T19:48:50Z")

</div>

Thanks! My only other question was the 2nd comment in this thread, I don’t understand the test-runner timeout constraint. I’ve tried to multithread my client etc. but to no avail; is it something on my end that should be optimzed?

---

<div class="post-metadata">

**Author:** ![Matt2843](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/matt2843/32/4832_2.png) [@Matt2843](https://forum.codecrafters.io/u/Matt2843)\
**Post date:** [February 11, 2025, 8:43pm UTC](https://forum.codecrafters.io/t/test-runner-is-giving-error-msg-provided-invalid-infohash-and-timeout-on-download/4794/6 "2025-02-11T20:43:46Z")

</div>

I digged a little bit into this (as I didn’t write the percent-encoding myself, it came from zig’s std’s Uri). Which implements RFC3986 ([RFC 3986: Uniform Resource Identifier (URI): Generic Syntax](https://www.rfc-editor.org/rfc/rfc3986#section-3.4))

Following the query-grammar of that RFC the byte=0x29 ascii `)` does not need to be percent-encoded nor does `&` which are the two characters that differ in the query-string. The grammar rules are here:

```auto
query = *( pchar / "/" / "?" )
pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
                       / "*" / "+" / "," / ";" / "="

```

So it seems like the agent’s web-server is non-compiant?

---

<div class="post-metadata">

**Author:** ![Matt2843](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/matt2843/32/4832_2.png) [@Matt2843](https://forum.codecrafters.io/u/Matt2843)\
**Post date:** [February 11, 2025, 9:10pm UTC](https://forum.codecrafters.io/t/test-runner-is-giving-error-msg-provided-invalid-infohash-and-timeout-on-download/4794/7 "2025-02-11T21:10:16Z")

</div>

I guess when used in a key-value pair query-string we want to encode the values, so we can interpret & as the separator. 🙂 i’ll just do it manually, the std.Uri in zig does not have any convenience in this regard. But I still wonder about the timeouts!
