# \[Rust\] Need Help with Timeout and Missing Logs in Program

**URL:** <https://forum.codecrafters.io/t/rust-need-help-with-timeout-and-missing-logs-in-program/3327>\
**Category:** Challenges\
**Tags:** challenge:kafka\
**Created:** [December 6, 2024, 6:06pm UTC](https://forum.codecrafters.io/t/rust-need-help-with-timeout-and-missing-logs-in-program/3327 "2024-12-06T18:06:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![skharchikov](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/skharchikov/32/3346_2.png) [@skharchikov](https://forum.codecrafters.io/u/skharchikov)\
**Post date:** [December 6, 2024, 6:06pm UTC](https://forum.codecrafters.io/t/rust-need-help-with-timeout-and-missing-logs-in-program/3327/1 "2024-12-06T18:06:26Z")

</div>

I’m stuck on Stage #pv1.

I’m running my program locally, and I can test that it’s working using the following command:

```bash
echo -n "000000230012674a4f74d28b00096b61666b612d636c69000a6b61666b612d636c6904302e3100" | xxd -r -p | nc localhost 9092 | hexdump -C  

```

My program locally prints in this case

```bash
Logs from your program will appear here!
Accepting connection
Received 39 bytes
Request: Request { message_size: 35, header: RequestHeader { api_key: 18, api_version: 26442, corelation_id: 1333056139, client_id: NullableString { length: -1, content: [] } } }
Response: Response { message_size: 19, header: ResponseHeader { corelation_id: 1333056139, error_code: 35, api_keys: [ApiKey { api_key: 18, min_version: 0, max_version: 4, tag_buffer: 0 }], throttle_time_ms: 420, tag_buffer: 0 } }
Response size: 19   

```

However, when I run `codecrafters test`, tests fail with a timeout error. Additionally, I can’t see any `println!` logs from my program, which makes debugging difficult.

Test output

```auto
[tester::#PV1] Running tests for Stage #PV1 (Handle APIVersions requests)
[tester::#PV1] $ ./your_program.sh /tmp/server.properties
[tester::#PV1] Connecting to broker at: localhost:9092
[your_program] Logs from your program will appear here!
[tester::#PV1] Connection to broker at localhost:9092 successful
[tester::#PV1] Sending "ApiVersions" (version: 4) request (Correlation id: 176388847)
[tester::#PV1] Hexdump of sent "ApiVersions" request: 
[tester::#PV1] Idx | Hex | ASCII
[tester::#PV1] -----+-------------------------------------------------+-----------------
[tester::#PV1] 0000 | 00 00 00 23 00 12 00 04 0a 83 7a ef 00 09 6b 61 | ...#......z...ka
[tester::#PV1] 0010 | 66 6b 61 2d 63 6c 69 00 0a 6b 61 66 6b 61 2d 63 | fka-cli..kafka-c
[tester::#PV1] 0020 | 6c 69 04 30 2e 31 00 | li.0.1.
[tester::#PV1] 
[your_program] Accepting connection
[tester::#PV1] timed out, test exceeded 10 seconds
[tester::#PV1] Test failed
[tester::#PV1] Terminating program
[tester::#PV1] Error terminating program: 'execution timed out'

```

Here’s the link to repo [GitHub - callmestech/callmestech-codecrafters-kafka-rust: Build your own Kafka using Rust](https://github.com/callmestech/callmestech-codecrafters-kafka-rust)

Does anyone have suggestions for troubleshooting this issue?

Thanks in advance!

---

<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:** [December 8, 2024, 11:25am UTC](https://forum.codecrafters.io/t/rust-need-help-with-timeout-and-missing-logs-in-program/3327/3 "2024-12-08T11:25:54Z")

</div>

Hi @skharchikov, `read_to_end` is problematic because it reads until `EOF` (end of file) or connection closure.

With TCP streams, there is no natural “end” - the connection stays open for continuous communication.

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

For Kafka protocol handling, we should read the message size first (4 bytes) and then read exactly that many bytes.

---

<div class="post-metadata">

**Author:** ![skharchikov](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/skharchikov/32/3346_2.png) [@skharchikov](https://forum.codecrafters.io/u/skharchikov)\
**Post date:** [December 8, 2024, 12:49pm UTC](https://forum.codecrafters.io/t/rust-need-help-with-timeout-and-missing-logs-in-program/3327/5 "2024-12-08T12:49:49Z")

</div>

Thank you so much! It does the trick!

---

<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:** [December 13, 2024, 12:49pm UTC](https://forum.codecrafters.io/t/rust-need-help-with-timeout-and-missing-logs-in-program/3327/6 "2024-12-13T12:49:56Z")

</div>

Closed on December 13, 2024, 12:49pm UTC

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