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

I’m stuck on Stage #pv1.

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

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

My program locally prints in this case

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

[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

Does anyone have suggestions for troubleshooting this issue?

Thanks in advance!

Hi @callmestech, 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.

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

1 Like

Thank you so much! It does the trick!

1 Like

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