[Rust] #PV1: Error reading from connection: unexpected eof

Hi, I tried migrating from std threads in rust to tokio tasks, it was going all well until I tried running previous tests, for some reason ApiVersions test is failing now with error “error reading from connection: unexpected eof” this is a client error as well, weird thing is, I’m getting this error in #PV1 stage only previous stage works fine. Since this is a protocol error, I’m guessing it should have affected previous stages too but they still pass the tests.
Github:
Repository: https://github.com/Jatinchhabra21/codecrafters-kafka-rust
Commit: https://github.com/Jatinchhabra21/codecrafters-kafka-rust/commit/544ce887c612851a434f6410dd20c352c0711277

Logs

Initiating test run...

⚡ This is a turbo test run. https://codecrafters.io/turbo

Running tests. Logs should appear shortly...

[compile]    Compiling kafka-starter-rust v0.1.0 (/app)
[compile] warning: struct `Fetch` is never constructed
[compile]  --> src/response/fetch.rs:3:12
[compile]   |
[compile] 3 | pub struct Fetch {
[compile]   |            ^^^^^
[compile]   |
[compile]   = note: `#[warn(dead_code)]` on by default
[compile]
[compile] warning: struct `Response` is never constructed
[compile]   --> src/response/fetch.rs:14:8
[compile]    |
[compile] 14 | struct Response {
[compile]    |        ^^^^^^^^
[compile]
[compile] warning: struct `Partition` is never constructed
[compile]   --> src/response/fetch.rs:20:8
[compile]    |
[compile] 20 | struct Partition {
[compile]    |        ^^^^^^^^^
[compile]
[compile] warning: struct `AbortedTransaction` is never constructed
[compile]   --> src/response/fetch.rs:31:8
[compile]    |
[compile] 31 | struct AbortedTransaction {
[compile]    |        ^^^^^^^^^^^^^^^^^^
[compile]
[compile] warning: associated function `new` is never used
[compile]   --> src/response/fetch.rs:37:12
[compile]    |
[compile] 36 | impl Fetch {
[compile]    | ---------- associated function in this implementation
[compile] 37 |     pub fn new(header: &RequestHeader) -> Fetch {
[compile]    |            ^^^
[compile]
[compile] warning: `kafka-starter-rust` (lib) generated 5 warnings
[compile] warning: unused import: `AsyncReadExt`
[compile]  --> src/main.rs:3:10
[compile]   |
[compile] 3 |     io::{AsyncReadExt, AsyncWriteExt},
[compile]   |          ^^^^^^^^^^^^
[compile]   |
[compile]   = note: `#[warn(unused_imports)]` on by default
[compile]
[compile] warning: unused import: `FETCH_REQUEST_API_KEY`
[compile]  --> src/main.rs:8:67
[compile]   |
[compile] 8 | use kafka_starter_rust::constants::{API_VERSIONS_REQUEST_API_KEY, FETCH_REQUEST_API_KEY};
[compile]   |                                                                   ^^^^^^^^^^^^^^^^^^^^^
[compile]
[compile] warning: `kafka-starter-rust` (bin "kafka-starter-rust") generated 2 warnings (run `cargo fix --bin "kafka-starter-rust"` to apply 2 suggestions)
[compile]     Finished release [optimized] target(s) in 2.85s
[compile] Moved ./.codecrafters/run.sh → ./your_program.sh
[compile] Compilation successful.

Debug = true

[tester::#VI6] Running tests for Stage #VI6 (Bind to a port)
[tester::#VI6] $ ./your_program.sh /tmp/server.properties
[tester::#VI6] Connecting to port 9092...
[your_program] Logs from your program will appear here!
[tester::#VI6] Connection successful
[tester::#VI6] Test passed.
[tester::#VI6] Terminating program
[tester::#VI6] Program terminated successfully

[tester::#NV3] Running tests for Stage #NV3 (Send Correlation ID)
[tester::#NV3] $ ./your_program.sh /tmp/server.properties
[tester::#NV3] Connecting to broker at: localhost:9092
[your_program] Logs from your program will appear here!
[tester::#NV3] Connection to broker at localhost:9092 successful
[tester::#NV3] Sending "ApiVersions" (version: 4) request (Correlation id: 7)
[tester::#NV3] Hexdump of sent "ApiVersions" request:
[tester::#NV3] Idx  | Hex                                             | ASCII
[tester::#NV3] -----+-------------------------------------------------+-----------------
[tester::#NV3] 0000 | 00 00 00 23 00 12 00 04 00 00 00 07 00 09 6b 61 | ...#..........ka
[tester::#NV3] 0010 | 66 6b 61 2d 63 6c 69 00 0a 6b 61 66 6b 61 2d 63 | fka-cli..kafka-c
[tester::#NV3] 0020 | 6c 69 04 30 2e 31 00                            | li.0.1.
[tester::#NV3]
[your_program] [DEBUG]: Reading first four bytes to get size of request
[your_program] [DEBUG]: Size of request - 35
[tester::#NV3] Hexdump of received "ApiVersions" response:
[tester::#NV3] Idx  | Hex                                             | ASCII
[tester::#NV3] -----+-------------------------------------------------+-----------------
[tester::#NV3] 0000 | 00 00 00 1a 00 00 00 07 00 00 03 00 12 00 00 00 | ................
[tester::#NV3] 0010 | 04 00 00 01 00 00 00 10 00 00 00 00 00          | .............
[tester::#NV3]
[tester::#NV3] [Decoder] - .Response
[tester::#NV3] [Decoder]   - .message_length (26)
[tester::#NV3] [Decoder] - .ResponseHeader
[your_program] [DEBUG]: Request bytes - [0, 18, 0, 4, 0, 0, 0, 7, 0, 9, 107, 97, 102, 107, 97, 45, 99, 108, 105, 0, 10, 107, 97, 102, 107, 97, 45, 99, 108, 105, 4, 48, 46, 49, 0]
[tester::#NV3] [Decoder]   - .correlation_id (7)
[tester::#NV3] ✓ Correlation ID: 7
[tester::#NV3] Test passed.
[tester::#NV3] Terminating program
[your_program] [DEBUG]: Writing to stream - [0, 0, 0, 26, 0, 0, 0, 7, 0, 0, 3, 0, 18, 0, 0, 0, 4, 0, 0, 1, 0, 0, 0, 16, 0, 0, 0, 0, 0]
[your_program] [DEBUG]: Write successfull.
[tester::#NV3] Program terminated successfully

[tester::#WA6] Running tests for Stage #WA6 (Parse Correlation ID)
[tester::#WA6] $ ./your_program.sh /tmp/server.properties
[tester::#WA6] Connecting to broker at: localhost:9092
[your_program] Logs from your program will appear here!
[tester::#WA6] Connection to broker at localhost:9092 successful
[tester::#WA6] Sending "ApiVersions" (version: 4) request (Correlation id: 519043073)
[tester::#WA6] Hexdump of sent "ApiVersions" request:
[tester::#WA6] Idx  | Hex                                             | ASCII
[tester::#WA6] -----+-------------------------------------------------+-----------------
[tester::#WA6] 0000 | 00 00 00 23 00 12 00 04 1e ef f8 01 00 09 6b 61 | ...#..........ka
[tester::#WA6] 0010 | 66 6b 61 2d 63 6c 69 00 0a 6b 61 66 6b 61 2d 63 | fka-cli..kafka-c
[tester::#WA6] 0020 | 6c 69 04 30 2e 31 00                            | li.0.1.
[tester::#WA6]
[tester::#WA6] Hexdump of received "ApiVersions" response:
[tester::#WA6] Idx  | Hex                                             | ASCII
[tester::#WA6] -----+-------------------------------------------------+-----------------
[tester::#WA6] 0000 | 00 00 00 1a 1e ef f8 01 00 00 03 00 12 00 00 00 | ................
[tester::#WA6] 0010 | 04 00 00 01 00 00 00 10 00 00 00 00 00          | .............
[tester::#WA6]
[tester::#WA6] [Decoder] - .Response
[tester::#WA6] [Decoder]   - .message_length (26)
[tester::#WA6] [Decoder] - .ResponseHeader
[tester::#WA6] [Decoder]   - .correlation_id (519043073)
[tester::#WA6] ✓ Correlation ID: 519043073
[tester::#WA6] Test passed.
[tester::#WA6] Terminating program
[your_program] [DEBUG]: Reading first four bytes to get size of request
[your_program] [DEBUG]: Size of request - 35
[your_program] [DEBUG]: Request bytes - [0, 18, 0, 4, 30, 239, 248, 1, 0, 9, 107, 97, 102, 107, 97, 45, 99, 108, 105, 0, 10, 107, 97, 102, 107, 97, 45, 99, 108, 105, 4, 48, 46, 49, 0]
[your_program] [DEBUG]: Writing to stream - [0, 0, 0, 26, 30, 239, 248, 1, 0, 0, 3, 0, 18, 0, 0, 0, 4, 0, 0, 1, 0, 0, 0, 16, 0, 0, 0, 0, 0]
[your_program] [DEBUG]: Write successfull.
[tester::#WA6] Program terminated successfully

[tester::#NC5] Running tests for Stage #NC5 (Parse API Version)
[tester::#NC5] $ ./your_program.sh /tmp/server.properties
[tester::#NC5] Connecting to broker at: localhost:9092
[your_program] Logs from your program will appear here!
[tester::#NC5] Connection to broker at localhost:9092 successful
[tester::#NC5] Sending "ApiVersions" (version: 26158) request (Correlation id: 370773480)
[tester::#NC5] Hexdump of sent "ApiVersions" request:
[tester::#NC5] Idx  | Hex                                             | ASCII
[tester::#NC5] -----+-------------------------------------------------+-----------------
[tester::#NC5] 0000 | 00 00 00 23 00 12 66 2e 16 19 8d e8 00 09 6b 61 | ...#..f.......ka
[tester::#NC5] 0010 | 66 6b 61 2d 63 6c 69 00 0a 6b 61 66 6b 61 2d 63 | fka-cli..kafka-c
[tester::#NC5] 0020 | 6c 69 04 30 2e 31 00                            | li.0.1.
[tester::#NC5]
[tester::#NC5] Hexdump of received "ApiVersions" response:
[tester::#NC5] Idx  | Hex                                             | ASCII
[tester::#NC5] -----+-------------------------------------------------+-----------------
[tester::#NC5] 0000 | 00 00 00 1a 16 19 8d e8 00 23 03 00 12 00 00 00 | .........#......
[tester::#NC5] 0010 | 04 00 00 01 00 00 00 10 00 00 00 00 00          | .............
[tester::#NC5]
[tester::#NC5] [Decoder] - .Response
[tester::#NC5] [Decoder]   - .message_length (26)
[tester::#NC5] [Decoder] - .ResponseHeader
[tester::#NC5] [Decoder]   - .correlation_id (370773480)
[tester::#NC5] [Decoder]   - .error_code (35)
[tester::#NC5] ✓ Correlation ID: 370773480
[tester::#NC5] ✓ Error code: 35 (UNSUPPORTED_VERSION)
[your_program] [DEBUG]: Reading first four bytes to get size of request
[your_program] [DEBUG]: Size of request - 35
[tester::#NC5] Test passed.
[tester::#NC5] Terminating program
[your_program] [DEBUG]: Request bytes - [0, 18, 102, 46, 22, 25, 141, 232, 0, 9, 107, 97, 102, 107, 97, 45, 99, 108, 105, 0, 10, 107, 97, 102, 107, 97, 45, 99, 108, 105, 4, 48, 46, 49, 0]
[your_program] [DEBUG]: Writing to stream - [0, 0, 0, 26, 22, 25, 141, 232, 0, 35, 3, 0, 18, 0, 0, 0, 4, 0, 0, 1, 0, 0, 0, 16, 0, 0, 0, 0, 0]
[your_program] [DEBUG]: Write successfull.
[tester::#NC5] Program terminated successfully

[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: 1447252425)
[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 56 43 51 c9 00 09 6b 61 | ...#....VCQ...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] [DEBUG]: Reading first four bytes to get size of request
[your_program] [DEBUG]: Size of request - 35
[your_program] [DEBUG]: Request bytes - [0, 18, 0, 4, 86, 67, 81, 201, 0, 9, 107, 97, 102, 107, 97, 45, 99, 108, 105, 0, 10, 107, 97, 102, 107, 97, 45, 99, 108, 105, 4, 48, 46, 49, 0]
[your_program] [DEBUG]: Writing to stream - [0, 0, 0, 26, 86, 67, 81, 201, 0, 0, 3, 0, 18, 0, 0, 0, 4, 0, 0, 1, 0, 0, 0, 16, 0, 0, 0, 0, 0]
[your_program] [DEBUG]: Write successfull.
[tester::#PV1] error reading from connection: unexpected EOF
[tester::#PV1] Test failed
[tester::#PV1] Terminating program
[tester::#PV1] Program terminated successfully

Hi, thanks for your post!

I’m currently out of the office and will return on Feb 3. I’ll get back to you as soon as possible after I’m back.